From 5aeba62bd0a8e5aaca6167c89aed6614991ce18d Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Thu, 28 Apr 2022 10:17:14 +0200 Subject: [PATCH 01/36] refactor(fullscreenrenderwindow, dataarray, remoteview, macro): refactor constructors Refactor of (some classes) constructors so that the setXXX() methods of coresponding properties are called when the classes are instanciated (calling newInstance). In the macro.js newInstance() function, the set() method is called in order that the setXXX() methods for each entry of initialValues is called if such methods exist. This is in order that side effects of setters are taken into account when creating new objects (for example through the call of modified()). Setters of both default and initial values are called. Refactor of DataArray and child classes. The method "setData" is called so that the parameters are synchronised as it is not a setter of one property in itself but has that purpose. Warning : it cannot be overwritten in child classes without possible issues of behavior when creating the object. Tests have been added and updated. A new test for macro protected properties have been added. BREAKING CHANGE: If a custom handling is done on the initialValues in the extend function, the changes made might be overwritten by the call of the set function in newInstace. If it is not what is intended, those properties have to be removed from initialValues after custom processing. If a setter of a property is called in the function creating an object (vtkObject(publicAPI, model)) such call should be removed to avoid witnessing twice the same side effects. --- Sources/Common/Core/CellArray/index.js | 6 +- Sources/Common/Core/DataArray/index.d.ts | 4 +- Sources/Common/Core/DataArray/index.js | 81 +++--- .../Core/DataArray/test/testDataArray.js | 233 +++++++++++++++++- Sources/Common/Core/Points/index.js | 21 +- Sources/Common/DataModel/Cell/index.js | 2 +- .../Common/DataModel/Cell/test/testCell.js | 2 +- Sources/Filters/Core/Cutter/index.js | 5 +- .../Filters/General/AppendPolyData/index.js | 1 + .../Misc/FullScreenRenderWindow/index.d.ts | 1 + .../Misc/FullScreenRenderWindow/index.js | 26 +- Sources/Rendering/Misc/RemoteView/index.js | 5 - Sources/Testing/testMacro.js | 118 +++++---- Sources/macros.js | 13 +- 14 files changed, 409 insertions(+), 109 deletions(-) diff --git a/Sources/Common/Core/CellArray/index.js b/Sources/Common/Core/CellArray/index.js index 504b0167974..706bf8859fd 100644 --- a/Sources/Common/Core/CellArray/index.js +++ b/Sources/Common/Core/CellArray/index.js @@ -18,6 +18,7 @@ function extractCellSizes(cellArray) { } function getNumberOfCells(cellArray) { + if (!cellArray) return 0; let cellId = 0; for (let cellArrayIndex = 0; cellArrayIndex < cellArray.length; ) { cellArrayIndex += cellArray[cellArrayIndex] + 1; @@ -88,6 +89,8 @@ function vtkCellArray(publicAPI, model) { function defaultValues(initialValues) { return { + // empty is only here to be passed to the DataArray extend function in order + // to create a cellArray without giving values empty: true, numberOfComponents: 1, dataType: VtkDataTypes.UNSIGNED_INT, @@ -98,7 +101,8 @@ function defaultValues(initialValues) { // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - vtkDataArray.extend(publicAPI, model, defaultValues(initialValues)); + Object.assign(initialValues, defaultValues(initialValues)); + vtkDataArray.extend(publicAPI, model, initialValues); vtkCellArray(publicAPI, model); } diff --git a/Sources/Common/Core/DataArray/index.d.ts b/Sources/Common/Core/DataArray/index.d.ts index 57b7469f6b1..35d4a33cc45 100644 --- a/Sources/Common/Core/DataArray/index.d.ts +++ b/Sources/Common/Core/DataArray/index.d.ts @@ -118,7 +118,7 @@ export interface vtkDataArray extends vtkObject { * @param {TypedArray} typedArray * @param {Number} [numberOfComponents] */ - setData(typedArray: TypedArray, numberOfComponents?: number): void; + setData(typedArray?: TypedArray, numberOfComponents?: number): void; /** * @@ -208,6 +208,8 @@ export function extend(publicAPI: object, model: object, initialValues?: object) /** * Method use to create a new instance of vtkDataArray * @param {object} [initialValues] for pre-setting some of its content + * initialValues can have a property "empty: true" to be able to create a + * model without giving data. This property will not be stored in the model */ export function newInstance(initialValues?: object): vtkDataArray; diff --git a/Sources/Common/Core/DataArray/index.js b/Sources/Common/Core/DataArray/index.js index b8f5bdf5236..231096edc51 100644 --- a/Sources/Common/Core/DataArray/index.js +++ b/Sources/Common/Core/DataArray/index.js @@ -239,9 +239,9 @@ function vtkDataArray(publicAPI, model) { publicAPI.getTupleLocation = (idx = 1) => idx * model.numberOfComponents; publicAPI.getNumberOfComponents = () => model.numberOfComponents; - publicAPI.getNumberOfValues = () => model.values.length; + publicAPI.getNumberOfValues = () => (model.values ? model.values.length : 0); publicAPI.getNumberOfTuples = () => - model.values.length / model.numberOfComponents; + model.values ? model.values.length / model.numberOfComponents : 0; publicAPI.getDataType = () => model.dataType; /* eslint-disable no-use-before-define */ publicAPI.newClone = () => @@ -261,10 +261,16 @@ function vtkDataArray(publicAPI, model) { return model.name; }; - publicAPI.setData = (typedArray, numberOfComponents) => { + publicAPI.setData = (typedArray = null, numberOfComponents = undefined) => { + if (Array.isArray(typedArray)) { + // eslint-disable-next-line no-param-reassign + typedArray = macro.newTypedArrayFrom(model.dataType, typedArray); + } + model.values = typedArray; - model.size = typedArray.length; - model.dataType = getDataType(typedArray); + model.size = typedArray ? typedArray.length : 0; + model.dataType = typedArray ? getDataType(typedArray) : model.dataType; + if (numberOfComponents) { model.numberOfComponents = numberOfComponents; } @@ -313,44 +319,63 @@ function vtkDataArray(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - name: '', - numberOfComponents: 1, - size: 0, - dataType: DefaultDataType, - rangeTuple: [0, 0], - // values: null, - // ranges: null, -}; +function defaultValues(initialValues) { + return { + name: '', + numberOfComponents: 1, + size: 0, + dataType: DefaultDataType, + rangeTuple: [0, 0], + // values: macro.newTypedArray(DefaultValues), + // ranges: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - - if (!model.empty && !model.values && !model.size) { + if (!initialValues.empty && !initialValues.values && !initialValues.size) { throw new TypeError( 'Cannot create vtkDataArray object without: size > 0, values' ); } - - if (!model.values) { - model.values = macro.newTypedArray(model.dataType, model.size); - } else if (Array.isArray(model.values)) { - model.values = macro.newTypedArrayFrom(model.dataType, model.values); - } - - if (model.values) { - model.size = model.values.length; - model.dataType = getDataType(model.values); - } + delete initialValues.empty; + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); macro.set(publicAPI, model, ['name', 'numberOfComponents']); + model.dataType = initialValues.dataType + ? initialValues.dataType + : DefaultDataType; + delete initialValues.dataType; + if (!initialValues.values) { + if (!initialValues.size) initialValues.values = null; + else + initialValues.values = macro.newTypedArray( + model.dataType, + initialValues.size + ); + } else if (Array.isArray(initialValues.values)) { + initialValues.values = macro.newTypedArrayFrom( + model.dataType, + initialValues.values + ); + } + // Object specific methods vtkDataArray(publicAPI, model); + + // We call customly setData here to keep coherence between parameters before + // the call of publicAPI.set(initialValues) in the constructor + // Warning : setData cannot be overwritten in a child class + publicAPI.setData(initialValues.values, initialValues.numberOfComponents); + delete initialValues.values; + delete initialValues.dataType; + delete initialValues.numberOfComponents; + delete initialValues.size; } // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/DataArray/test/testDataArray.js b/Sources/Common/Core/DataArray/test/testDataArray.js index fc7c7a40376..fe5aee86270 100644 --- a/Sources/Common/Core/DataArray/test/testDataArray.js +++ b/Sources/Common/Core/DataArray/test/testDataArray.js @@ -1,10 +1,239 @@ import test from 'tape-catch'; import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; +import Constants from 'vtk.js/Sources/Common/Core/DataArray/Constants'; +import * as macro from 'vtk.js/Sources/macros'; + +const { DefaultDataType } = Constants; + +function getDataArrayProperties(dataArray) { + return { + size: dataArray.get().size, + numberOfComponents: dataArray.get().numberOfComponents, + dataType: dataArray.get().dataType, + values: dataArray.get().values, + }; +} test('Test vtkDataArray instance', (t) => { t.ok(vtkDataArray, 'Make sure the class definition exists'); - const instance = vtkDataArray.newInstance({ size: 256 }); - t.ok(instance); + + t.throws( + () => vtkDataArray.newInstance({}), + 'Not allowed to create instance without initialValues' + ); + + t.doesNotThrow( + () => vtkDataArray.newInstance({ empty: true }), + 'Allowed to create instance with empty true, no data' + ); + + t.throws( + () => vtkDataArray.newInstance({ empty: false }), + 'Not allowed to create instance with empty false, no data' + ); + + t.doesNotThrow( + () => vtkDataArray.newInstance({ size: 256 }), + 'Allowed to create instance with only size' + ); + + const dataArray0 = vtkDataArray.newInstance({ + empty: true, + values: null, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 1, + values: null, + }, + getDataArrayProperties(dataArray0), + 'initialValues.data = null' + ); + + const dataArray1 = vtkDataArray.newInstance({ size: 256 }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 256, + numberOfComponents: 1, + values: macro.newTypedArray(DefaultDataType, 256), + }, + getDataArrayProperties(dataArray1), + 'Give only size to create instance' + ); + + const dataArray2 = vtkDataArray.newInstance({ + values: Uint32Array.from([1, 2, 3]), + }); + t.deepEqual( + { + dataType: 'Uint32Array', + size: 3, + numberOfComponents: 1, + values: Uint32Array.from([1, 2, 3]), + }, + getDataArrayProperties(dataArray2), + 'Create instance with data (typed array)' + ); + + const dataArray3 = vtkDataArray.newInstance({ + values: [1, 2, 3], + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 1, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3]), + }, + getDataArrayProperties(dataArray3), + 'Create instance with data (untyped array)' + ); + + const dataArray4 = vtkDataArray.newInstance({ + values: [1, 2, 3, 4, 5, 6, 7, 8, 9], + numberOfComponents: 3, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 9, + numberOfComponents: 3, + values: macro.newTypedArrayFrom( + DefaultDataType, + [1, 2, 3, 4, 5, 6, 7, 8, 9] + ), + }, + getDataArrayProperties(dataArray4), + 'Change number of components at instanciation' + ); + + const dataArray5 = vtkDataArray.newInstance({ + values: [1, 2, 3], + dataType: null, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 1, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3]), + }, + getDataArrayProperties(dataArray5), + 'Give null as dataType' + ); + + const dataArray6 = vtkDataArray.newInstance({ + empty: true, + values: null, + numberOfComponents: 3, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 3, + values: null, + }, + getDataArrayProperties(dataArray6), + 'Give numberOfComponents!=1 with empty array' + ); + + t.end(); +}); + +test('Test vtkDataArray setData', (t) => { + const dataArray = vtkDataArray.newInstance({ empty: true }); + + dataArray.setData([4, 5, 6, 7]); + t.deepEqual( + { + dataType: DefaultDataType, + size: 4, + numberOfComponents: 1, + values: macro.newTypedArrayFrom(DefaultDataType, [4, 5, 6, 7]), + }, + getDataArrayProperties(dataArray), + 'Change data of existing instance' + ); + + dataArray.setData([1, 2, 3, 4, 5, 6], 2); + t.deepEqual( + { + dataType: DefaultDataType, + size: 6, + numberOfComponents: 2, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3, 4, 5, 6]), + }, + getDataArrayProperties(dataArray), + 'Change number of components with setData' + ); + + dataArray.setData([1, 2, 3, 4], 3); + t.deepEqual( + { + dataType: DefaultDataType, + size: 4, + numberOfComponents: 1, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3, 4]), + }, + getDataArrayProperties(dataArray), + 'Change number of components with setData but wrong numberOfComponents' + ); + + dataArray.setData([]); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 1, + values: macro.newTypedArray(DefaultDataType), + }, + getDataArrayProperties(dataArray), + 'Empty an instance (pass [] array)' + ); + + // Fill the DataArray before so that we are sure the size and the numberOfComponents are updated + dataArray.setData([1, 2, 3], 3); + dataArray.setData(null); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 3, + values: null, + }, + getDataArrayProperties(dataArray), + 'Call setData with typedArray = null' + ); + + // Fill the DataArray before so that we are sure the size and the numberOfComponents are updated + dataArray.setData([1, 2, 3], 3); + dataArray.setData(); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 3, + values: null, + }, + getDataArrayProperties(dataArray), + 'Call setData with typedArray = undefined' + ); + + dataArray.setData(macro.newTypedArrayFrom('Uint32Array', [4, 5, 6, 7])); + t.deepEqual( + { + dataType: 'Uint32Array', + size: 4, + numberOfComponents: 1, + values: macro.newTypedArrayFrom('Uint32Array', [4, 5, 6, 7]), + }, + getDataArrayProperties(dataArray), + 'Change data of existing instance with another type' + ); t.end(); }); diff --git a/Sources/Common/Core/Points/index.js b/Sources/Common/Core/Points/index.js index b3f71e46f7f..b3e4665e2b6 100644 --- a/Sources/Common/Core/Points/index.js +++ b/Sources/Common/Core/Points/index.js @@ -80,18 +80,23 @@ function vtkPoints(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - empty: true, - numberOfComponents: 3, - dataType: VtkDataTypes.FLOAT, - bounds: [1, -1, 1, -1, 1, -1], -}; +function defaultValues(initialValues) { + return { + // empty is only here to be passed to the DataArray extend function in order + // to create Points without giving values + empty: true, + numberOfComponents: 3, + dataType: VtkDataTypes.FLOAT, + bounds: [1, -1, 1, -1, 1, -1], + values: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - + Object.assign(initialValues, defaultValues(initialValues)); vtkDataArray.extend(publicAPI, model, initialValues); vtkPoints(publicAPI, model); } diff --git a/Sources/Common/DataModel/Cell/index.js b/Sources/Common/DataModel/Cell/index.js index c1f537ff6e9..43a821e4878 100644 --- a/Sources/Common/DataModel/Cell/index.js +++ b/Sources/Common/DataModel/Cell/index.js @@ -135,7 +135,7 @@ export function extend(publicAPI, model, initialValues = {}) { macro.obj(publicAPI, model); if (!model.points) { - model.points = vtkPoints.newInstance(); + model.points = vtkPoints.newInstance({ values: [] }); } macro.get(publicAPI, model, ['points', 'pointsIds']); diff --git a/Sources/Common/DataModel/Cell/test/testCell.js b/Sources/Common/DataModel/Cell/test/testCell.js index 751426f978e..97789f26bc2 100644 --- a/Sources/Common/DataModel/Cell/test/testCell.js +++ b/Sources/Common/DataModel/Cell/test/testCell.js @@ -53,7 +53,7 @@ test('Test vtkCell deepCopy', (t) => { cell.initialize(points); const cell2 = vtkCell.newInstance(); - cell2.deepCopy(cell); + cell.deepCopy(cell2); t.notEqual(cell2.getPoints(), points); t.deepEqual(cell2.getPoints().getData(), points.getData()); diff --git a/Sources/Filters/Core/Cutter/index.js b/Sources/Filters/Core/Cutter/index.js index ef1e2cc39e5..05d046b99a4 100644 --- a/Sources/Filters/Core/Cutter/index.js +++ b/Sources/Filters/Core/Cutter/index.js @@ -6,6 +6,7 @@ const { vtkErrorMacro } = macro; function initPolyIterator(pd) { const polys = pd.getPolys().getData(); const strips = pd.getStrips().getData(); + const stripsLength = strips ? strips.length : 0; const it = { done: false, polyIdx: 0, @@ -20,7 +21,7 @@ function initPolyIterator(pd) { const end = start + cellSize; it.polyIdx = end; ret = polys.subarray(start, end); - } else if (it.stripIdx < strips.length) { + } else if (it.stripIdx < stripsLength) { if (it.remainingStripLength === 0) { it.remainingStripLength = strips[it.stripIdx] - 2; // sliding window of 3 points // stripIdx points to the last point in a triangle 3-tuple @@ -35,7 +36,7 @@ function initPolyIterator(pd) { throw new Error('Iterator is done'); } - it.done = it.polyIdx >= polys.length && it.stripIdx >= strips.length; + it.done = it.polyIdx >= polys.length && it.stripIdx >= stripsLength; return ret; }, }; diff --git a/Sources/Filters/General/AppendPolyData/index.js b/Sources/Filters/General/AppendPolyData/index.js index d7cbb3de981..1fa6145ac99 100644 --- a/Sources/Filters/General/AppendPolyData/index.js +++ b/Sources/Filters/General/AppendPolyData/index.js @@ -10,6 +10,7 @@ const { vtkErrorMacro } = macro; function offsetCellArray(typedArray, offset) { let currentIdx = 0; + if (!typedArray) return {}; return typedArray.map((value, index) => { if (index === currentIdx) { currentIdx += value + 1; diff --git a/Sources/Rendering/Misc/FullScreenRenderWindow/index.d.ts b/Sources/Rendering/Misc/FullScreenRenderWindow/index.d.ts index 1298a1576e7..dfedc2d0f0f 100644 --- a/Sources/Rendering/Misc/FullScreenRenderWindow/index.d.ts +++ b/Sources/Rendering/Misc/FullScreenRenderWindow/index.d.ts @@ -128,6 +128,7 @@ export function extend(publicAPI: object, model: object, initialValues?: IFullSc /** * Method used to create a new instance of vtkFullScreenRenderWindow * @param {IFullScreenRenderWindowInitialValues} [initialValues] for pre-setting some of its content + * a background property can be given in the initialValues to set the background of the renderer */ export function newInstance(initialValues?: IFullScreenRenderWindowInitialValues): vtkFullScreenRenderWindow; diff --git a/Sources/Rendering/Misc/FullScreenRenderWindow/index.js b/Sources/Rendering/Misc/FullScreenRenderWindow/index.js index 067c089b580..a16affd059f 100644 --- a/Sources/Rendering/Misc/FullScreenRenderWindow/index.js +++ b/Sources/Rendering/Misc/FullScreenRenderWindow/index.js @@ -94,8 +94,8 @@ function vtkFullScreenRenderWindow(publicAPI, model) { model.interactor.initialize(); model.interactor.bindEvents(model.container); - // Expose background publicAPI.setBackground = model.renderer.setBackground; + publicAPI.getBackground = model.renderer.getBackground; publicAPI.removeController = () => { const el = model.controlContainer; @@ -137,9 +137,6 @@ function vtkFullScreenRenderWindow(publicAPI, model) { }); }; - // Update BG color - publicAPI.setBackground(...model.background); - // Representation API publicAPI.addRepresentation = (representation) => { representation.getActors().forEach((actor) => { @@ -188,19 +185,22 @@ function vtkFullScreenRenderWindow(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - background: [0.32, 0.34, 0.43], - containerStyle: null, - controlPanelStyle: null, - listenWindowResize: true, - resizeCallback: null, - controllerVisibility: true, -}; +function defaultValues(initialValues) { + return { + background: [0.32, 0.34, 0.43], + containerStyle: null, + controlPanelStyle: null, + listenWindowResize: true, + resizeCallback: null, + controllerVisibility: true, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Misc/RemoteView/index.js b/Sources/Rendering/Misc/RemoteView/index.js index a60e8e96646..1845ee1b189 100644 --- a/Sources/Rendering/Misc/RemoteView/index.js +++ b/Sources/Rendering/Misc/RemoteView/index.js @@ -181,11 +181,6 @@ function vtkRemoteView(publicAPI, model) { } return changeDetected; }; - - // Initialize viewStream if available - if (model.viewStream) { - publicAPI.setViewStream(model.viewStream); - } } // ---------------------------------------------------------------------------- diff --git a/Sources/Testing/testMacro.js b/Sources/Testing/testMacro.js index d1118059079..88dc438dd29 100644 --- a/Sources/Testing/testMacro.js +++ b/Sources/Testing/testMacro.js @@ -21,25 +21,42 @@ function myClass(publicAPI, model) { // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - myProp1: [0, 0, 0], - myProp2: null, // Do not initialize internal objects here - myProp3: true, - myProp4: 6, - myProp5: [1, 2, 3, 4], - myProp6: [0.1, 0.2, 0.3, 0.4, 0.5], - myProp7: MY_ENUM.FIRST, - myProp8: [1, 2, 3], - myProp9: null, - // myProp10: null, - myProp11: 11, - _myProp12: [12], - _myProp13: 13, -}; +function defaultValues(initialValues) { + return { + myProp1: [0, 0, 0], + myProp2: null, // Do not initialize internal objects here + myProp3: true, + myProp4: 6, + myProp5: [1, 2, 3, 4], + myProp6: [0.1, 0.2, 0.3, 0.4, 0.5], + myProp7: MY_ENUM.FIRST, + myProp8: [1, 2, 3], + myProp9: null, + // myProp10: null, + myProp11: 11, + _myProp12: [12], + _myProp13: 13, + myProp14: 14, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + const defaults = defaultValues(); + macro.moveToProtected(publicAPI, initialValues, [ + 'myProp11', + 'myProp12', + 'myProp13', + 'myProp14', + ]); + macro.moveToProtected(publicAPI, defaults, [ + 'myProp11', + 'myProp12', + 'myProp13', + 'myProp14', + ]); + Object.assign(initialValues, defaults, { ...initialValues }); // Object methods macro.obj(publicAPI, model); @@ -72,7 +89,12 @@ function extend(publicAPI, model, initialValues = {}) { // Protected variables macro.setGet(publicAPI, model, ['_myProp11']); macro.setGetArray(publicAPI, model, ['_myProp12'], 1); - macro.moveToProtected(publicAPI, model, ['myProp11', 'myProp12', 'myProp13']); + macro.moveToProtected(publicAPI, initialValues, [ + 'myProp11', + 'myProp12', + 'myProp13', + 'myProp14', + ]); // Object specific methods myClass(publicAPI, model); @@ -93,7 +115,7 @@ test('Macro methods scalar tests', (t) => { t.equal( myTestClass.getMyProp3(), - DEFAULT_VALUES.myProp3, + defaultValues().myProp3, 'Initial gets should match defaults' ); myTestClass.setMyProp3(false); @@ -102,7 +124,7 @@ test('Macro methods scalar tests', (t) => { const mtime1 = myTestClass.getMTime(); t.equal( myTestClass.getMyProp4(), - DEFAULT_VALUES.myProp4, + defaultValues().myProp4, 'Initial gets should match defaults' ); myTestClass.setMyProp4(42); @@ -121,7 +143,7 @@ test('Macro methods array tests', (t) => { t.deepEqual( myTestClass.getMyProp1(), - DEFAULT_VALUES.myProp1, + defaultValues().myProp1, 'Initial gets should match defaults' ); // we must wrap the non-existent call inside another function to avoid test program exiting, and tape-catch generating error. @@ -155,7 +177,7 @@ test('Macro methods array tests', (t) => { ); t.deepEqual( myTestClass.getMyProp6(), - DEFAULT_VALUES.myProp6, + defaultValues().myProp6, 'Keep default value after illegal set' ); @@ -290,9 +312,9 @@ test('Macro methods array tests', (t) => { test('Macro protected variables tests', (t) => { const defaultInstance = newInstance(); t.deepEqual(defaultInstance.get('_myProp11', '_myProp12', '_myProp13'), { - _myProp11: DEFAULT_VALUES.myProp11, - _myProp12: DEFAULT_VALUES._myProp12, - _myProp13: DEFAULT_VALUES._myProp13, + _myProp11: defaultValues().myProp11, + _myProp12: defaultValues()._myProp12, + _myProp13: defaultValues()._myProp13, }); // getter must have been renamed t.notOk(defaultInstance.get_myProp11); @@ -304,8 +326,8 @@ test('Macro protected variables tests', (t) => { t.notOk(defaultInstance.set_myProp12); t.notOk(defaultInstance.set_myProp13); - t.equal(defaultInstance.getMyProp11(), DEFAULT_VALUES.myProp11); - t.deepEqual(defaultInstance.getMyProp12(), DEFAULT_VALUES._myProp12); + t.equal(defaultInstance.getMyProp11(), defaultValues().myProp11); + t.deepEqual(defaultInstance.getMyProp12(), defaultValues()._myProp12); t.notOk(defaultInstance.getMyProp13); t.notOk(defaultInstance.getMyProp11ByReference); @@ -327,22 +349,32 @@ test('Macro protected variables tests', (t) => { myProp11: 111, myProp12: [112], myProp13: 113, + myProp14: 114, }); - t.deepEqual(overridenInstance.get('_myProp11', '_myProp12', '_myProp13'), { - _myProp11: 111, - _myProp12: [112], - _myProp13: 113, - }); + t.deepEqual( + overridenInstance.get('_myProp11', '_myProp12', '_myProp13', '_myProp14'), + { + _myProp11: 111, + _myProp12: [112], + _myProp13: 113, + _myProp14: 114, + } + ); const overridenInstance2 = newInstance({ _myProp11: 111, _myProp12: [112], _myProp13: 113, + _myProp14: 114, }); - t.deepEqual(overridenInstance2.get('_myProp11', '_myProp12', '_myProp13'), { - _myProp11: DEFAULT_VALUES.myProp11, // TBD - _myProp12: [112], - _myProp13: 113, - }); + t.deepEqual( + overridenInstance2.get('_myProp11', '_myProp12', '_myProp13', '_myProp14'), + { + _myProp11: 111, + _myProp12: [112], + _myProp13: 113, + _myProp14: 114, + } + ); t.end(); }); @@ -351,7 +383,7 @@ test('Macro methods enum tests', (t) => { t.equal( myTestClass.getMyProp7(), - DEFAULT_VALUES.myProp7, + defaultValues().myProp7, 'Initial gets should match defaults' ); myTestClass.setMyProp7(MY_ENUM.THIRD); @@ -408,14 +440,16 @@ test('Macro methods enum tests', (t) => { test('Macro methods object tests', (t) => { const myTestClass = newInstance(); - const defaultValues = { ...DEFAULT_VALUES }; - defaultValues._myProp11 = defaultValues.myProp11; - delete defaultValues.myProp11; + const copyDefaultValues = { ...defaultValues() }; + copyDefaultValues._myProp11 = copyDefaultValues.myProp11; + copyDefaultValues._myProp14 = copyDefaultValues.myProp14; + delete copyDefaultValues.myProp11; + delete copyDefaultValues.myProp14; t.ok(myTestClass.get(), 'Get entire model'); t.deepEqual( - myTestClass.get(...Object.keys(defaultValues)), - defaultValues, + myTestClass.get(...Object.keys(copyDefaultValues)), + copyDefaultValues, 'Get defaults back test' ); diff --git a/Sources/macros.js b/Sources/macros.js index c7bc3cbaf74..e4977e12b0f 100644 --- a/Sources/macros.js +++ b/Sources/macros.js @@ -309,7 +309,7 @@ export function obj(publicAPI = {}, model = {}) { publicAPI.set = (map = {}, noWarning = false, noFunction = false) => { let ret = false; Object.keys(map).forEach((name) => { - const fn = noFunction ? null : publicAPI[`set${capitalize(name)}`]; + const fn = noFunction ? null : publicAPI[`set${_capitalize(name)}`]; if (fn && Array.isArray(map[name]) && fn.length > 1) { ret = fn(...map[name]) || ret; } else if (fn) { @@ -639,12 +639,14 @@ export function setGetArray( setArray(publicAPI, model, fieldNames, size, defaultVal); } -export function moveToProtected(publicAPI, model, fieldNames) { +export function moveToProtected(publicAPI, values, fieldNames) { for (let i = 0; i < fieldNames.length; i++) { const fieldName = fieldNames[i]; - if (model[fieldName] !== undefined) { - model[`_${fieldName}`] = model[fieldName]; - delete model[fieldName]; + if (values[fieldName] !== undefined) { + if (values[`_${fieldName}`] === undefined) { + values[`_${fieldName}`] = values[fieldName]; + } + delete values[fieldName]; } } } @@ -972,6 +974,7 @@ export function newInstance(extend, className) { const model = {}; const publicAPI = {}; extend(publicAPI, model, initialValues); + publicAPI.set(initialValues, true); return Object.freeze(publicAPI); }; From 4f77c691254af2781d8bf9c01c95774f771caf8f Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 31 May 2022 12:01:40 +0200 Subject: [PATCH 02/36] feat(testmacro): defaultValues have protected values named with underscore defaultValues have to have protected values named with underscore to avoid having them to be moved to protected --- Sources/Testing/testMacro.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Sources/Testing/testMacro.js b/Sources/Testing/testMacro.js index 88dc438dd29..ced286fa72b 100644 --- a/Sources/Testing/testMacro.js +++ b/Sources/Testing/testMacro.js @@ -33,30 +33,23 @@ function defaultValues(initialValues) { myProp8: [1, 2, 3], myProp9: null, // myProp10: null, - myProp11: 11, + _myProp11: 11, _myProp12: [12], _myProp13: 13, - myProp14: 14, + _myProp14: 14, ...initialValues, }; } // ---------------------------------------------------------------------------- function extend(publicAPI, model, initialValues = {}) { - const defaults = defaultValues(); macro.moveToProtected(publicAPI, initialValues, [ 'myProp11', 'myProp12', 'myProp13', 'myProp14', ]); - macro.moveToProtected(publicAPI, defaults, [ - 'myProp11', - 'myProp12', - 'myProp13', - 'myProp14', - ]); - Object.assign(initialValues, defaults, { ...initialValues }); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); @@ -312,7 +305,7 @@ test('Macro methods array tests', (t) => { test('Macro protected variables tests', (t) => { const defaultInstance = newInstance(); t.deepEqual(defaultInstance.get('_myProp11', '_myProp12', '_myProp13'), { - _myProp11: defaultValues().myProp11, + _myProp11: defaultValues()._myProp11, _myProp12: defaultValues()._myProp12, _myProp13: defaultValues()._myProp13, }); @@ -326,7 +319,7 @@ test('Macro protected variables tests', (t) => { t.notOk(defaultInstance.set_myProp12); t.notOk(defaultInstance.set_myProp13); - t.equal(defaultInstance.getMyProp11(), defaultValues().myProp11); + t.equal(defaultInstance.getMyProp11(), defaultValues()._myProp11); t.deepEqual(defaultInstance.getMyProp12(), defaultValues()._myProp12); t.notOk(defaultInstance.getMyProp13); From a89d4daf74870ee6f03e405a62a336f2a84d05cc Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Fri, 3 Jun 2022 12:07:51 +0200 Subject: [PATCH 03/36] fix(hardwareselector, renderwindow): fix after refactor Change to put properties in initialValues to call setters on them. Handle null or undefined in some setters. --- .../Common/DataModel/SelectionNode/index.js | 28 ++++--- Sources/Rendering/Core/Actor/index.js | 40 +++++---- .../Rendering/Core/HardwareSelector/index.js | 23 +++--- Sources/Rendering/Core/Prop/index.js | 48 ++++++----- Sources/Rendering/Core/Prop3D/index.js | 77 +++++++++-------- Sources/Rendering/OpenGL/Actor/index.js | 31 +++---- .../OpenGL/HardwareSelector/index.js | 50 +++++------ .../Rendering/OpenGL/RenderWindow/index.js | 82 +++++++++---------- Sources/Rendering/OpenGL/Renderer/index.js | 28 ++++--- .../Rendering/SceneGraph/RenderPass/index.js | 39 +++++---- .../SceneGraph/RenderWindowViewNode/index.js | 26 +++--- .../Rendering/SceneGraph/ViewNode/index.js | 33 ++++---- .../SceneGraph/ViewNodeFactory/index.js | 21 +++-- Sources/Rendering/WebGPU/Actor/index.js | 33 ++++---- .../WebGPU/HardwareSelectionPass/index.js | 25 +++--- .../WebGPU/HardwareSelector/index.js | 21 +++-- 16 files changed, 330 insertions(+), 275 deletions(-) diff --git a/Sources/Common/DataModel/SelectionNode/index.js b/Sources/Common/DataModel/SelectionNode/index.js index ed01bf26ddf..d8e2fa964b2 100644 --- a/Sources/Common/DataModel/SelectionNode/index.js +++ b/Sources/Common/DataModel/SelectionNode/index.js @@ -1,6 +1,19 @@ import macro from 'vtk.js/Sources/macros'; import Constants from 'vtk.js/Sources/Common/DataModel/SelectionNode/Constants'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + contentType: -1, + fieldType: -1, + selectionList: [], + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkSelectionNode methods // ---------------------------------------------------------------------------- @@ -12,25 +25,14 @@ function vtkSelectionNode(publicAPI, model) { publicAPI.getBounds = () => model.points.getBounds(); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - contentType: -1, - fieldType: -1, - properties: null, - selectionList: [], -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance macro.obj(publicAPI, model); - model.properties = {}; + initialValues.properties = {}; macro.setGet(publicAPI, model, [ 'contentType', 'fieldType', diff --git a/Sources/Rendering/Core/Actor/index.js b/Sources/Rendering/Core/Actor/index.js index 43f769187f6..aa9634043a9 100644 --- a/Sources/Rendering/Core/Actor/index.js +++ b/Sources/Rendering/Core/Actor/index.js @@ -6,6 +6,25 @@ import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property'; const { vtkDebugMacro } = macro; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + mapper: null, + property: null, + backfaceProperty: null, + + forceOpaque: false, + forceTranslucent: false, + + bounds: [1, -1, 1, -1, 1, -1], + + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkActor methods // ---------------------------------------------------------------------------- @@ -166,32 +185,17 @@ function vtkActor(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - mapper: null, - property: null, - backfaceProperty: null, - - forceOpaque: false, - forceTranslucent: false, - - bounds: [1, -1, 1, -1, 1, -1], -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkProp3D.extend(publicAPI, model, initialValues); // vtkTimeStamp - model.boundsMTime = {}; - macro.obj(model.boundsMTime); + initialValues.boundsMTime = {}; + macro.obj(initialValues.boundsMTime); // Build VTK API macro.set(publicAPI, model, ['property']); diff --git a/Sources/Rendering/Core/HardwareSelector/index.js b/Sources/Rendering/Core/HardwareSelector/index.js index 76abb383cc0..ea9830d2960 100644 --- a/Sources/Rendering/Core/HardwareSelector/index.js +++ b/Sources/Rendering/Core/HardwareSelector/index.js @@ -3,6 +3,18 @@ import vtkDataSet from 'vtk.js/Sources/Common/DataModel/DataSet'; const { FieldAssociations } = vtkDataSet; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + fieldAssociation: FieldAssociations.FIELD_ASSOCIATION_CELLS, + captureZValues: false, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkHardwareSelector methods // ---------------------------------------------------------------------------- @@ -31,19 +43,10 @@ function vtkHardwareSelector(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - fieldAssociation: FieldAssociations.FIELD_ASSOCIATION_CELLS, - captureZValues: false, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Prop/index.js b/Sources/Rendering/Core/Prop/index.js index 41ccf2ca755..93e1ee55acf 100644 --- a/Sources/Rendering/Core/Prop/index.js +++ b/Sources/Rendering/Core/Prop/index.js @@ -4,6 +4,27 @@ function notImplemented(method) { return () => macro.vtkErrorMacro(`vtkProp::${method} - NOT IMPLEMENTED`); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // _parentProp: null, + visibility: true, + pickable: true, + dragable: true, + useBounds: true, + allocatedRenderTime: 10, + estimatedRenderTime: 0, + savedEstimatedRenderTime: 0, + renderTimeMultiplier: 1, + paths: null, + textures: [], + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkProp methods // ---------------------------------------------------------------------------- @@ -13,9 +34,10 @@ function vtkProp(publicAPI, model) { model.classHierarchy.push('vtkProp'); publicAPI.getMTime = () => { + const textures = model.textures ? model.textures : defaultValues().textures; let m1 = model.mtime; - for (let index = 0; index < model.textures.length; ++index) { - const m2 = model.textures[index].getMTime(); + for (let index = 0; index < textures.length; ++index) { + const m2 = textures[index].getMTime(); if (m2 > m1) { m1 = m2; } @@ -89,28 +111,11 @@ function vtkProp(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - // _parentProp: null, - visibility: true, - pickable: true, - dragable: true, - useBounds: true, - allocatedRenderTime: 10, - estimatedRenderTime: 0, - savedEstimatedRenderTime: 0, - renderTimeMultiplier: 1, - paths: null, - textures: [], -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, ['parentProp']); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -123,7 +128,6 @@ export function extend(publicAPI, model, initialValues = {}) { 'renderTimeMultiplier', '_parentProp', ]); - macro.moveToProtected(publicAPI, model, ['parentProp']); // Object methods vtkProp(publicAPI, model); diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index adc7bd9ca1b..adf084d8d16 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -5,6 +5,26 @@ import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox'; import * as vtkMath from 'vtk.js/Sources/Common/Core/Math'; import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + origin: [0, 0, 0], + position: [0, 0, 0], + orientation: [0, 0, 0], + scale: [1, 1, 1], + bounds: [1, -1, 1, -1, 1, -1], + + userMatrixMTime: null, + + cachedProp3D: null, + isIdentity: true, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkProp3D methods // ---------------------------------------------------------------------------- @@ -83,6 +103,7 @@ function vtkProp3D(publicAPI, model) { publicAPI.setOrientation = (x, y, z) => { if ( + model.orientation && x === model.orientation[0] && y === model.orientation[1] && z === model.orientation[2] @@ -90,6 +111,7 @@ function vtkProp3D(publicAPI, model) { return false; } model.orientation = [x, y, z]; + if (!model.rotation) model.rotation = mat4.identity(new Float64Array(16)); mat4.identity(model.rotation); publicAPI.rotateZ(z); publicAPI.rotateX(x); @@ -99,7 +121,13 @@ function vtkProp3D(publicAPI, model) { }; publicAPI.setUserMatrix = (matrix) => { - mat4.copy(model.userMatrix, matrix); + if (!matrix) { + model.userMatrix = null; + } else { + if (!model.userMatrix) + model.userMatrix = mat4.identity(new Float64Array(16)); + mat4.copy(model.userMatrix, matrix); + } publicAPI.modified(); }; @@ -110,21 +138,26 @@ function vtkProp3D(publicAPI, model) { publicAPI.computeMatrix = () => { // check whether or not need to rebuild the matrix + if (!model.matrixMTime) { + return; + } if (publicAPI.getMTime() > model.matrixMTime.getMTime()) { mat4.identity(model.matrix); if (model.userMatrix) { mat4.multiply(model.matrix, model.matrix, model.userMatrix); } - mat4.translate(model.matrix, model.matrix, model.origin); - mat4.translate(model.matrix, model.matrix, model.position); - mat4.multiply(model.matrix, model.matrix, model.rotation); - mat4.scale(model.matrix, model.matrix, model.scale); - mat4.translate(model.matrix, model.matrix, [ - -model.origin[0], - -model.origin[1], - -model.origin[2], - ]); - mat4.transpose(model.matrix, model.matrix); + if (model.position && model.origin && model.scale && model.rotation) { + mat4.translate(model.matrix, model.matrix, model.origin); + mat4.translate(model.matrix, model.matrix, model.position); + mat4.multiply(model.matrix, model.matrix, model.rotation); + mat4.scale(model.matrix, model.matrix, model.scale); + mat4.translate(model.matrix, model.matrix, [ + -model.origin[0], + -model.origin[1], + -model.origin[2], + ]); + mat4.transpose(model.matrix, model.matrix); + } // check for identity model.isIdentity = true; @@ -154,30 +187,10 @@ function vtkProp3D(publicAPI, model) { publicAPI.onModified(updateIdentityFlag); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - origin: [0, 0, 0], - position: [0, 0, 0], - orientation: [0, 0, 0], - rotation: null, - scale: [1, 1, 1], - bounds: [1, -1, 1, -1, 1, -1], - - userMatrix: null, - userMatrixMTime: null, - - cachedProp3D: null, - isIdentity: true, - matrixMTime: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkProp.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/OpenGL/Actor/index.js b/Sources/Rendering/OpenGL/Actor/index.js index c62ee1ab395..c00d638d1ef 100644 --- a/Sources/Rendering/OpenGL/Actor/index.js +++ b/Sources/Rendering/OpenGL/Actor/index.js @@ -5,6 +5,18 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + context: null, + activeTextures: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkOpenGLActor methods // ---------------------------------------------------------------------------- @@ -180,28 +192,17 @@ function vtkOpenGLActor(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - context: null, - keyMatrixTime: null, - keyMatrices: null, - activeTextures: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.keyMatrixTime = {}; - macro.obj(model.keyMatrixTime, { mtime: 0 }); - model.keyMatrices = { + initialValues.keyMatrixTime = {}; + macro.obj(initialValues.keyMatrixTime, { mtime: 0 }); + initialValues.keyMatrices = { normalMatrix: mat3.identity(new Float64Array(9)), mcwc: mat4.identity(new Float64Array(16)), }; diff --git a/Sources/Rendering/OpenGL/HardwareSelector/index.js b/Sources/Rendering/OpenGL/HardwareSelector/index.js index 27f52f627cd..327d5e73cc6 100644 --- a/Sources/Rendering/OpenGL/HardwareSelector/index.js +++ b/Sources/Rendering/OpenGL/HardwareSelector/index.js @@ -329,6 +329,22 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { ); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + area: undefined, + // _renderer: null, + // _openGLRenderWindow: null, + // _openGLRenderer: null, + currentPass: -1, + idOffset: 1, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkOpenGLHardwareSelector methods // ---------------------------------------------------------------------------- @@ -876,6 +892,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) { // override const superSetArea = publicAPI.setArea; publicAPI.setArea = (...args) => { + if (!args[0]) return false; + if (!model.area) 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]); @@ -887,36 +905,23 @@ function vtkOpenGLHardwareSelector(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - area: undefined, - // _renderer: null, - // _openGLRenderWindow: null, - // _openGLRenderer: null, - currentPass: -1, - propColorValue: null, - props: null, - maximumPointId: 0, - maximumCellId: 0, - idOffset: 1, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, [ + 'renderer', + 'openGLRenderWindow', + ]); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API vtkHardwareSelector.extend(publicAPI, model, initialValues); - model.propColorValue = [0, 0, 0]; - model.props = []; + initialValues.propColorValue = [0, 0, 0]; + initialValues.props = []; - if (!model.area) { - model.area = [0, 0, 0, 0]; + if (!initialValues.area) { + initialValues.area = [0, 0, 0, 0]; } macro.setGetArray(publicAPI, model, ['area'], 4); @@ -929,7 +934,6 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.setGetArray(publicAPI, model, ['propColorValue'], 3); - macro.moveToProtected(publicAPI, model, ['renderer', 'openGLRenderWindow']); macro.event(publicAPI, model, 'event'); // Object methods diff --git a/Sources/Rendering/OpenGL/RenderWindow/index.js b/Sources/Rendering/OpenGL/RenderWindow/index.js index 273b78e32f5..00d88127fb2 100644 --- a/Sources/Rendering/OpenGL/RenderWindow/index.js +++ b/Sources/Rendering/OpenGL/RenderWindow/index.js @@ -82,6 +82,35 @@ 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 // ---------------------------------------------------------------------------- @@ -118,8 +147,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) { // Canvas size if (model.renderable) { if ( - model.size[0] !== previousSize[0] || - model.size[1] !== previousSize[1] + model.size && + (model.size[0] !== previousSize[0] || model.size[1] !== previousSize[1]) ) { previousSize[0] = model.size[0]; previousSize[1] = model.size[1]; @@ -573,7 +602,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) { publicAPI.setUseBackgroundImage = (value) => { model.useBackgroundImage = value; - + if (!model.el) return; // Add or remove the background image from the // DOM as specified. if (model.useBackgroundImage && !model.el.contains(model.bgImage)) { @@ -1220,39 +1249,10 @@ function vtkOpenGLRenderWindow(publicAPI, model) { ); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - cullFaceEnabled: false, - shaderCache: null, - initialized: false, - context: null, - canvas: null, - cursorVisibility: true, - cursor: 'pointer', - textureUnitManager: null, - textureResourceIds: 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, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkRenderWindowViewNode.extend(publicAPI, model, initialValues); @@ -1262,9 +1262,9 @@ export function extend(publicAPI, model, initialValues = {}) { model.canvas.style.width = '100%'; createGLContext(); - if (!model.selector) { - model.selector = vtkOpenGLHardwareSelector.newInstance(); - model.selector.setOpenGLRenderWindow(publicAPI); + if (!initialValues.selector) { + initialValues.selector = vtkOpenGLHardwareSelector.newInstance(); + initialValues.selector.setOpenGLRenderWindow(publicAPI); } // Create internal bgImage @@ -1278,16 +1278,16 @@ export function extend(publicAPI, model, initialValues = {}) { model._textureResourceIds = new Map(); - model.myFactory = vtkOpenGLViewNodeFactory.newInstance(); + initialValues.myFactory = vtkOpenGLViewNodeFactory.newInstance(); /* eslint-disable no-use-before-define */ - model.myFactory.registerOverride('vtkRenderWindow', newInstance); + initialValues.myFactory.registerOverride('vtkRenderWindow', newInstance); /* eslint-enable no-use-before-define */ - model.shaderCache = vtkShaderCache.newInstance(); - model.shaderCache.setOpenGLRenderWindow(publicAPI); + initialValues.shaderCache = vtkShaderCache.newInstance(); + initialValues.shaderCache.setOpenGLRenderWindow(publicAPI); // setup default forward pass rendering - model.renderPasses[0] = vtkForwardPass.newInstance(); + initialValues.renderPasses[0] = vtkForwardPass.newInstance(); macro.event(publicAPI, model, 'imageReady'); macro.event(publicAPI, model, 'haveVRDisplay'); diff --git a/Sources/Rendering/OpenGL/Renderer/index.js b/Sources/Rendering/OpenGL/Renderer/index.js index 4e9e3b19999..ad36e4b30dc 100644 --- a/Sources/Rendering/OpenGL/Renderer/index.js +++ b/Sources/Rendering/OpenGL/Renderer/index.js @@ -5,6 +5,19 @@ import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactor const { vtkDebugMacro } = macro; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + context: null, + // _openGLRenderWindow: null, + selector: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkOpenGLRenderer methods // ---------------------------------------------------------------------------- @@ -184,20 +197,11 @@ function vtkOpenGLRenderer(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - context: null, - // _openGLRenderWindow: null, - selector: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, ['openGLRenderWindow']); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); @@ -207,8 +211,6 @@ export function extend(publicAPI, model, initialValues = {}) { macro.setGet(publicAPI, model, ['selector']); - macro.moveToProtected(publicAPI, model, ['openGLRenderWindow']); - // Object methods vtkOpenGLRenderer(publicAPI, model); } diff --git a/Sources/Rendering/SceneGraph/RenderPass/index.js b/Sources/Rendering/SceneGraph/RenderPass/index.js index d8a41f89c93..0b2888ebbdc 100644 --- a/Sources/Rendering/SceneGraph/RenderPass/index.js +++ b/Sources/Rendering/SceneGraph/RenderPass/index.js @@ -1,5 +1,20 @@ import macro from 'vtk.js/Sources/macros'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + delegates: [], + currentOperation: null, + preDelegateOperations: [], + postDelegateOperations: [], + currentParent: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- function vtkRenderPass(publicAPI, model) { @@ -10,9 +25,13 @@ function vtkRenderPass(publicAPI, model) { publicAPI.setCurrentOperation = (val) => { model.currentOperation = val; - model.currentTraverseOperation = `traverse${macro.capitalize( - model.currentOperation - )}`; + if (!val) { + model.currentTraverseOperation = undefined; + } else { + model.currentTraverseOperation = `traverse${macro.capitalize( + model.currentOperation + )}`; + } }; publicAPI.getTraverseOperation = () => model.currentTraverseOperation; @@ -43,22 +62,10 @@ function vtkRenderPass(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - delegates: [], - currentOperation: null, - preDelegateOperations: [], - postDelegateOperations: [], - currentParent: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index b415c147e33..25a9c4e15c0 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -9,6 +9,17 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; // view try to limit such interactions to methods defined in this class. // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + selector: undefined, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkRenderWindowViewNode methods // ---------------------------------------------------------------------------- @@ -146,22 +157,13 @@ function vtkRenderWindowViewNode(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - size: undefined, - selector: undefined, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); - if (!model.size) { - model.size = [300, 300]; + if (!initialValues.size) { + initialValues.size = [300, 300]; } macro.getArray(publicAPI, model, ['size'], 2); diff --git a/Sources/Rendering/SceneGraph/ViewNode/index.js b/Sources/Rendering/SceneGraph/ViewNode/index.js index 55847486b64..a0eff8a2ce4 100644 --- a/Sources/Rendering/SceneGraph/ViewNode/index.js +++ b/Sources/Rendering/SceneGraph/ViewNode/index.js @@ -4,6 +4,21 @@ const { vtkErrorMacro } = macro; const PASS_TYPES = ['Build', 'Render']; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // _parent: null, + renderable: null, + myFactory: null, + children: [], + visited: false, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkViewNode methods // ---------------------------------------------------------------------------- @@ -186,33 +201,21 @@ function vtkViewNode(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - // _parent: null, - renderable: null, - myFactory: null, - children: [], - visited: false, -}; - // ---------------------------------------------------------------------------- function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, ['parent']); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); macro.event(publicAPI, model, 'event'); - model._renderableChildMap = new Map(); + initialValues._renderableChildMap = new Map(); macro.get(publicAPI, model, ['visited']); macro.setGet(publicAPI, model, ['_parent', 'renderable', 'myFactory']); macro.getArray(publicAPI, model, ['children']); - macro.moveToProtected(publicAPI, model, ['parent']); // Object methods vtkViewNode(publicAPI, model); diff --git a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js index 06b1497e390..c188a53f45d 100644 --- a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js +++ b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js @@ -1,5 +1,16 @@ import macro from 'vtk.js/Sources/macros'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // overrides: {}, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkViewNodeFactory methods // ---------------------------------------------------------------------------- @@ -43,18 +54,10 @@ function vtkViewNodeFactory(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - // overrides: {}, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/WebGPU/Actor/index.js b/Sources/Rendering/WebGPU/Actor/index.js index 1acc67ad693..13932ae6125 100644 --- a/Sources/Rendering/WebGPU/Actor/index.js +++ b/Sources/Rendering/WebGPU/Actor/index.js @@ -5,6 +5,18 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; import { registerOverride } from 'vtk.js/Sources/Rendering/WebGPU/ViewNodeFactory'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + propID: undefined, + bufferShift: undefined, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkWebGPUActor methods // ---------------------------------------------------------------------------- @@ -148,28 +160,17 @@ function vtkWebGPUActor(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - keyMatricesTime: null, - keyMatrices: null, - propID: undefined, - bufferShift: undefined, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.keyMatricesTime = {}; - macro.obj(model.keyMatricesTime, { mtime: 0 }); - model.keyMatrices = { + initialValues.keyMatricesTime = {}; + macro.obj(initialValues.keyMatricesTime, { mtime: 0 }); + initialValues.keyMatrices = { normalMatrix: new Float64Array(16), bcwc: new Float64Array(16), bcsc: new Float64Array(16), @@ -177,7 +178,7 @@ export function extend(publicAPI, model, initialValues = {}) { macro.get(publicAPI, model, ['propID', 'keyMatricesTime']); - model.bufferShift = [0, 0, 0, 0]; + initialValues.bufferShift = [0, 0, 0, 0]; // Object methods vtkWebGPUActor(publicAPI, model); diff --git a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js index eecc2dd21ad..ba9ef4cc8d2 100644 --- a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js @@ -4,6 +4,19 @@ import vtkWebGPUTexture from 'vtk.js/Sources/Rendering/WebGPU/Texture'; import vtkWebGPUShaderCache from 'vtk.js/Sources/Rendering/WebGPU/ShaderCache'; import vtkRenderPass from 'vtk.js/Sources/Rendering/SceneGraph/RenderPass'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + selectionRenderEncoder: null, + colorTexture: null, + depthTexture: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- function vtkWebGPUHardwareSelectionPass(publicAPI, model) { @@ -116,20 +129,10 @@ function vtkWebGPUHardwareSelectionPass(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - selectionRenderEncoder: null, - colorTexture: null, - depthTexture: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API vtkRenderPass.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/WebGPU/HardwareSelector/index.js b/Sources/Rendering/WebGPU/HardwareSelector/index.js index b4d7db83bd8..49ae8d54110 100644 --- a/Sources/Rendering/WebGPU/HardwareSelector/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelector/index.js @@ -252,6 +252,17 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { return convertSelection(buffdata.fieldAssociation, dataMap, buffdata); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + WebGPURenderWindow: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkWebGPUHardwareSelector methods // ---------------------------------------------------------------------------- @@ -413,18 +424,10 @@ function vtkWebGPUHardwareSelector(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - WebGPURenderWindow: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API vtkHardwareSelector.extend(publicAPI, model, initialValues); From ff88fd840bf06a4063306522b1099154f2212dc7 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 8 Jun 2022 09:39:18 +0200 Subject: [PATCH 04/36] fix(actor2d): change constructor to call setters call setters at instanciation. Modify also related classes --- Sources/Common/Core/LookupTable/index.js | 57 ++++++------ .../DataModel/DataSetAttributes/FieldData.js | 67 ++++++++------ Sources/Filters/Sources/CubeSource/index.js | 23 ++--- Sources/Filters/Sources/SphereSource/index.js | 29 +++--- .../Rendering/Core/AbstractMapper/index.js | 18 ++-- Sources/Rendering/Core/Actor/index.js | 8 +- Sources/Rendering/Core/Actor2D/index.js | 41 +++++---- Sources/Rendering/Core/Camera/index.js | 89 ++++++++++++------- Sources/Rendering/Core/Coordinate/index.js | 41 +++++---- Sources/Rendering/Core/Light/index.js | 38 ++++---- Sources/Rendering/Core/Mapper/index.js | 57 ++++++------ Sources/Rendering/Core/Mapper2D/index.js | 39 ++++---- Sources/Rendering/Core/Prop3D/index.js | 4 + Sources/Rendering/Core/Property/index.js | 56 ++++++------ Sources/Rendering/Core/Property2D/index.js | 21 +++-- Sources/Rendering/Core/RenderWindow/index.js | 21 +++-- Sources/Rendering/Core/Renderer/index.js | 87 +++++++++--------- Sources/Rendering/Core/Viewport/index.js | 27 +++--- Sources/Rendering/OpenGL/Actor2D/index.js | 13 +-- Sources/Rendering/OpenGL/Camera/index.js | 17 ++-- Sources/Rendering/OpenGL/Shader/index.js | 21 +++-- Sources/Rendering/OpenGL/ShaderCache/index.js | 20 +++-- .../Rendering/OpenGL/ShaderProgram/index.js | 49 +++++----- .../Rendering/OpenGL/ViewNodeFactory/index.js | 8 +- Sources/Rendering/WebGPU/Camera/index.js | 19 ++-- .../Rendering/WebGPU/RenderWindow/index.js | 46 +++++----- Sources/Rendering/WebGPU/Renderer/index.js | 21 +++-- Sources/Rendering/WebGPU/ShaderCache/index.js | 15 ++-- .../Rendering/WebGPU/ViewNodeFactory/index.js | 6 +- 29 files changed, 534 insertions(+), 424 deletions(-) diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index f80a7ad5047..04534165723 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -294,43 +294,40 @@ function vtkLookupTable(publicAPI, model) { publicAPI.forceBuild(); } }; - - if (model.table.length > 0) { - // ensure insertTime is more recently modified than buildTime if - // a table is provided via the constructor - model.insertTime.modified(); - } } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - numberOfColors: 256, - // table: null, - - hueRange: [0.0, 0.66667], - saturationRange: [1.0, 1.0], - valueRange: [1.0, 1.0], - alphaRange: [1.0, 1.0], - - nanColor: [0.5, 0.0, 0.0, 1.0], - belowRangeColor: [0.0, 0.0, 0.0, 1.0], - aboveRangeColor: [1.0, 1.0, 1.0, 1.0], - useAboveRangeColor: false, - useBelowRangeColor: false, - - alpha: 1.0, - // buildTime: null, - // opaqueFlagBuildTime: null, - // insertTime: null, -}; +function defaultValues(initialValues) { + return { + numberOfColors: 256, + // table: null, + + hueRange: [0.0, 0.66667], + saturationRange: [1.0, 1.0], + valueRange: [1.0, 1.0], + alphaRange: [1.0, 1.0], + + nanColor: [0.5, 0.0, 0.0, 1.0], + belowRangeColor: [0.0, 0.0, 0.0, 1.0], + aboveRangeColor: [1.0, 1.0, 1.0, 1.0], + useAboveRangeColor: false, + useBelowRangeColor: false, + + alpha: 1.0, + // buildTime: null, + // opaqueFlagBuildTime: null, + // insertTime: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkScalarsToColors.extend(publicAPI, model, initialValues); @@ -389,6 +386,12 @@ export function extend(publicAPI, model, initialValues = {}) { // Object specific methods vtkLookupTable(publicAPI, model); + + if (initialValues.table && initialValues.table.length > 0) { + // ensure insertTime is more recently modified than buildTime if + // a table is provided via the constructor + model.insertTime.modified(); + } } // ---------------------------------------------------------------------------- diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index 0658ef16ec8..0ccdb65ed0c 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -10,11 +10,6 @@ function vtkFieldData(publicAPI, model) { model.classHierarchy.push('vtkFieldData'); const superGetState = publicAPI.getState; - // Decode serialized data if any - if (model.arrays) { - model.arrays = model.arrays.map((item) => ({ data: vtk(item.data) })); - } - publicAPI.initialize = () => { publicAPI.initializeFields(); publicAPI.copyAllOn(); @@ -57,22 +52,28 @@ function vtkFieldData(publicAPI, model) { ? publicAPI.getArrayByIndex(arraySpec) : publicAPI.getArrayByName(arraySpec); publicAPI.getArrayByName = (arrayName) => - model.arrays.reduce( - (a, b, i) => (b.data.getName() === arrayName ? b.data : a), - null - ); + model.arrays + ? model.arrays.reduce( + (a, b, i) => (b.data.getName() === arrayName ? b.data : a), + null + ) + : null; publicAPI.getArrayWithIndex = (arrayName) => - model.arrays.reduce( - (a, b, i) => - b.data && b.data.getName() === arrayName - ? { array: b.data, index: i } - : a, - { array: null, index: -1 } - ); + model.arrays + ? model.arrays.reduce( + (a, b, i) => + b.data && b.data.getName() === arrayName + ? { array: b.data, index: i } + : a, + { array: null, index: -1 } + ) + : null; publicAPI.getArrayByIndex = (idx) => idx >= 0 && idx < model.arrays.length ? model.arrays[idx].data : null; - publicAPI.hasArray = (arrayName) => - publicAPI.getArrayWithIndex(arrayName).index >= 0; + publicAPI.hasArray = (arrayName) => { + const array = publicAPI.getArrayWithIndex(arrayName); + return array && array.index >= 0; + }; publicAPI.getArrayName = (idx) => { const arr = model.arrays[idx]; return arr ? arr.data.getName() : ''; @@ -158,11 +159,13 @@ function vtkFieldData(publicAPI, model) { // TODO: publicAPI.squeeze = () => model.arrays.forEach(entry => entry.data.squeeze()); publicAPI.reset = () => model.arrays.forEach((entry) => entry.data.reset()); // TODO: getActualMemorySize - publicAPI.getMTime = () => - model.arrays.reduce( + publicAPI.getMTime = () => { + if (!model.arrays) return 0; + return model.arrays.reduce( (a, b) => (b.data.getMTime() > a ? b.data.getMTime() : a), model.mtime ); + }; // TODO: publicAPI.getField = (ids, other) => { copy ids from other into this model's arrays } // TODO: publicAPI.getArrayContainingComponent = (component) => ... publicAPI.getNumberOfComponents = () => @@ -181,19 +184,29 @@ function vtkFieldData(publicAPI, model) { }; } -const DEFAULT_VALUES = { - arrays: [], - copyFieldFlags: [], // fields not to copy - doCopyAllOn: true, - doCopyAllOff: false, -}; +function defaultValues(initialValues) { + return { + arrays: [], + copyFieldFlags: [], // fields not to copy + doCopyAllOn: true, + doCopyAllOff: false, + ...initialValues, + }; +} export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); macro.obj(publicAPI, model); vtkFieldData(publicAPI, model); + + // Decode serialized data if any + if (initialValues.arrays) { + initialValues.arrays = initialValues.arrays.map((item) => ({ + data: vtk(item.data), + })); + } } // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/CubeSource/index.js b/Sources/Filters/Sources/CubeSource/index.js index 331d866b427..40db9915653 100644 --- a/Sources/Filters/Sources/CubeSource/index.js +++ b/Sources/Filters/Sources/CubeSource/index.js @@ -267,20 +267,23 @@ function vtkCubeSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - xLength: 1.0, - yLength: 1.0, - zLength: 1.0, - center: [0.0, 0.0, 0.0], - rotations: [0.0, 0.0, 0.0], - pointType: 'Float64Array', - generate3DTextureCoordinates: false, -}; +function defaultValues(initialValues) { + return { + xLength: 1.0, + yLength: 1.0, + zLength: 1.0, + center: [0.0, 0.0, 0.0], + rotations: [0.0, 0.0, 0.0], + pointType: 'Float64Array', + generate3DTextureCoordinates: false, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/SphereSource/index.js b/Sources/Filters/Sources/SphereSource/index.js index d06008f16da..264daa3819c 100644 --- a/Sources/Filters/Sources/SphereSource/index.js +++ b/Sources/Filters/Sources/SphereSource/index.js @@ -201,23 +201,26 @@ function vtkSphereSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - radius: 0.5, - latLongTessellation: false, - thetaResolution: 8, - startTheta: 0.0, - endTheta: 360.0, - phiResolution: 8, - startPhi: 0.0, - endPhi: 180.0, - center: [0, 0, 0], - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + radius: 0.5, + latLongTessellation: false, + thetaResolution: 8, + startTheta: 0.0, + endTheta: 360.0, + phiResolution: 8, + startPhi: 0.0, + endPhi: 180.0, + center: [0, 0, 0], + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/AbstractMapper/index.js b/Sources/Rendering/Core/AbstractMapper/index.js index d3930694237..c1f05c69325 100644 --- a/Sources/Rendering/Core/AbstractMapper/index.js +++ b/Sources/Rendering/Core/AbstractMapper/index.js @@ -22,7 +22,8 @@ function vtkAbstractMapper(publicAPI, model) { return false; }; - publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length; + publicAPI.getNumberOfClippingPlanes = () => + model.clippingPlanes ? model.clippingPlanes.length : 0; publicAPI.removeAllClippingPlanes = () => { model.clippingPlanes.length = 0; @@ -89,21 +90,24 @@ function vtkAbstractMapper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - clippingPlanes: [], -}; +function defaultValues(initialValues) { + return { + clippingPlanes: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); macro.algo(publicAPI, model, 1, 0); - if (!model.clippingPlanes) { - model.clippingPlanes = []; + if (!initialValues.clippingPlanes) { + initialValues.clippingPlanes = []; } vtkAbstractMapper(publicAPI, model); diff --git a/Sources/Rendering/Core/Actor/index.js b/Sources/Rendering/Core/Actor/index.js index aa9634043a9..d080dc48b7f 100644 --- a/Sources/Rendering/Core/Actor/index.js +++ b/Sources/Rendering/Core/Actor/index.js @@ -147,12 +147,12 @@ function vtkActor(publicAPI, model) { publicAPI.getMTime = () => { let mt = superClass.getMTime(); - if (model.property !== null) { + if (model.property) { const time = model.property.getMTime(); mt = time > mt ? time : mt; } - if (model.backfaceProperty !== null) { + if (model.backfaceProperty) { const time = model.backfaceProperty.getMTime(); mt = time > mt ? time : mt; } @@ -194,8 +194,8 @@ export function extend(publicAPI, model, initialValues = {}) { vtkProp3D.extend(publicAPI, model, initialValues); // vtkTimeStamp - initialValues.boundsMTime = {}; - macro.obj(initialValues.boundsMTime); + model.boundsMTime = {}; + macro.obj(model.boundsMTime); // Build VTK API macro.set(publicAPI, model, ['property']); diff --git a/Sources/Rendering/Core/Actor2D/index.js b/Sources/Rendering/Core/Actor2D/index.js index d66fdedbd8b..ee9b3b3cde2 100644 --- a/Sources/Rendering/Core/Actor2D/index.js +++ b/Sources/Rendering/Core/Actor2D/index.js @@ -4,6 +4,19 @@ import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop'; import vtkProperty2D from 'vtk.js/Sources/Rendering/Core/Property2D'; import { Coordinate } from 'vtk.js/Sources/Rendering/Core/Coordinate/Constants'; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + mapper: null, + property: null, + layerNumber: 0, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkActor2D methods // ---------------------------------------------------------------------------- @@ -133,32 +146,22 @@ function vtkActor2D(publicAPI, model) { publicAPI.getActualPositionCoordinate2 = () => model.positionCoordinate2; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - mapper: null, - property: null, - layerNumber: 0, - positionCoordinate: null, - positionCoordinate2: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkProp.extend(publicAPI, model, initialValues); - model.positionCoordinate = vtkCoordinate.newInstance(); - model.positionCoordinate.setCoordinateSystemToViewport(); - model.positionCoordinate2 = vtkCoordinate.newInstance(); - model.positionCoordinate2.setCoordinateSystemToNormalizedViewport(); - model.positionCoordinate2.setValue(0.5, 0.5); - model.positionCoordinate2.setReferenceCoordinate(model.positionCoordinate); + initialValues.positionCoordinate = vtkCoordinate.newInstance(); + initialValues.positionCoordinate.setCoordinateSystemToViewport(); + initialValues.positionCoordinate2 = vtkCoordinate.newInstance(); + initialValues.positionCoordinate2.setCoordinateSystemToNormalizedViewport(); + initialValues.positionCoordinate2.setValue(0.5, 0.5); + initialValues.positionCoordinate2.setReferenceCoordinate( + initialValues.positionCoordinate + ); // Build VTK API macro.set(publicAPI, model, ['property']); diff --git a/Sources/Rendering/Core/Camera/index.js b/Sources/Rendering/Core/Camera/index.js index 0afae14541a..eb4b1520d32 100644 --- a/Sources/Rendering/Core/Camera/index.js +++ b/Sources/Rendering/Core/Camera/index.js @@ -17,6 +17,41 @@ const { vtkDebugMacro } = macro; // return matrix[idx]; // } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +export function defaultValues(initialValues) { + return { + position: [0, 0, 1], + focalPoint: [0, 0, 0], + viewUp: [0, 1, 0], + directionOfProjection: [0, 0, -1], + parallelProjection: false, + useHorizontalViewAngle: false, + viewAngle: 30, + parallelScale: 1, + clippingRange: [0.01, 1000.01], + windowCenter: [0, 0], + viewPlaneNormal: [0, 0, 1], + useOffAxisProjection: false, + screenBottomLeft: [-0.5, -0.5, -0.5], + screenBottomRight: [0.5, -0.5, -0.5], + screenTopRight: [0.5, 0.5, -0.5], + freezeFocalPoint: false, + projectionMatrix: null, + viewMatrix: null, + cameraLightTransform: mat4.create(), + + // used for world to physical transformations + physicalTranslation: [0, 0, 0], + physicalScale: 1.0, + physicalViewUp: [0, 1, 0], + physicalViewNorth: [0, 0, -1], + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkCamera methods // ---------------------------------------------------------------------------- @@ -42,6 +77,7 @@ function vtkCamera(publicAPI, model) { // Internal Functions that don't need to be public function computeViewPlaneNormal() { + if (!model.viewPlaneNormal) model.viewPlaneNormal = [0, 0, 0]; // VPN is -DOP model.viewPlaneNormal[0] = -model.directionOfProjection[0]; model.viewPlaneNormal[1] = -model.directionOfProjection[1]; @@ -59,12 +95,16 @@ function vtkCamera(publicAPI, model) { publicAPI.setPosition = (x, y, z) => { if ( + model.position && x === model.position[0] && y === model.position[1] && z === model.position[2] ) { return; } + if (!model.position) { + model.position = defaultValues().position; + } model.position[0] = x; model.position[1] = y; @@ -77,6 +117,7 @@ function vtkCamera(publicAPI, model) { publicAPI.setFocalPoint = (x, y, z) => { if ( + model.focalPoint && x === model.focalPoint[0] && y === model.focalPoint[1] && z === model.focalPoint[2] @@ -118,12 +159,22 @@ function vtkCamera(publicAPI, model) { //---------------------------------------------------------------------------- // This method must be called when the focal point or camera position changes publicAPI.computeDistance = () => { + if (!model.position) { + model.position = defaultValues().position; + } + if (!model.focalPoint) { + model.focalPoint = defaultValues().focalPoint; + } const dx = model.focalPoint[0] - model.position[0]; const dy = model.focalPoint[1] - model.position[1]; const dz = model.focalPoint[2] - model.position[2]; model.distance = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (!model.directionOfProjection) { + model.directionOfProjection = defaultValues().directionOfProjection; + } + if (model.distance < 1e-20) { model.distance = 1e-20; vtkDebugMacro('Distance is set to minimum.'); @@ -682,7 +733,9 @@ function vtkCamera(publicAPI, model) { let vn = null; let position = null; - vn = model.viewPlaneNormal; + vn = model.viewPlaneNormal + ? model.viewPlaneNormal + : defaultValues().viewPlaneNormal; position = model.position; const a = -vn[0]; @@ -709,42 +762,10 @@ function vtkCamera(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -export const DEFAULT_VALUES = { - position: [0, 0, 1], - focalPoint: [0, 0, 0], - viewUp: [0, 1, 0], - directionOfProjection: [0, 0, -1], - parallelProjection: false, - useHorizontalViewAngle: false, - viewAngle: 30, - parallelScale: 1, - clippingRange: [0.01, 1000.01], - windowCenter: [0, 0], - viewPlaneNormal: [0, 0, 1], - useOffAxisProjection: false, - screenBottomLeft: [-0.5, -0.5, -0.5], - screenBottomRight: [0.5, -0.5, -0.5], - screenTopRight: [0.5, 0.5, -0.5], - freezeFocalPoint: false, - projectionMatrix: null, - viewMatrix: null, - cameraLightTransform: mat4.create(), - - // used for world to physical transformations - physicalTranslation: [0, 0, 0], - physicalScale: 1.0, - physicalViewUp: [0, 1, 0], - physicalViewNorth: [0, 0, -1], -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Coordinate/index.js b/Sources/Rendering/Core/Coordinate/index.js index 691c5189e30..a544bf95a48 100644 --- a/Sources/Rendering/Core/Coordinate/index.js +++ b/Sources/Rendering/Core/Coordinate/index.js @@ -33,14 +33,18 @@ function vtkCoordinate(publicAPI, model) { throw new RangeError('Invalid number of values for array setter'); } let changeDetected = false; - model.value.forEach((item, index) => { - if (item !== array[index]) { - if (changeDetected) { - return; + if (model.value) { + model.value.forEach((item, index) => { + if (item !== array[index]) { + if (changeDetected) { + return; + } + changeDetected = true; } - changeDetected = true; - } - }); + }); + } else { + changeDetected = true; + } if (changeDetected) { model.value = [].concat(array); @@ -581,20 +585,23 @@ function vtkCoordinate(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - coordinateSystem: Coordinate.WORLD, - value: [0.0, 0.0, 0.0], - renderer: null, - referenceCoordinate: null, - computing: 0, - computedWorldValue: [0.0, 0.0, 0.0], - computedDoubleDisplayValue: [0.0, 0.0], -}; +function defaultValues(initialValues) { + return { + coordinateSystem: Coordinate.WORLD, + value: [0.0, 0.0, 0.0], + renderer: null, + referenceCoordinate: null, + computing: 0, + computedWorldValue: [0.0, 0.0, 0.0], + computedDoubleDisplayValue: [0.0, 0.0], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Light/index.js b/Sources/Rendering/Core/Light/index.js index ac367f07f81..07f22bdf059 100644 --- a/Sources/Rendering/Core/Light/index.js +++ b/Sources/Rendering/Core/Light/index.js @@ -87,27 +87,31 @@ function vtkLight(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - switch: true, - intensity: 1, - color: [1, 1, 1], - position: [0, 0, 1], - focalPoint: [0, 0, 0], - positional: false, - exponent: 1, - coneAngle: 30, - attenuationValues: [1, 0, 0], - transformMatrix: null, - lightType: 'SceneLight', - shadowAttenuation: 1, - direction: [0, 0, 0], - directionMTime: 0, -}; +function defaultValues(initialValues) { + return { + switch: true, + intensity: 1, + color: [1, 1, 1], + position: [0, 0, 1], + focalPoint: [0, 0, 0], + positional: false, + exponent: 1, + coneAngle: 30, + attenuationValues: [1, 0, 0], + transformMatrix: null, + lightType: 'SceneLight', + shadowAttenuation: 1, + direction: [0, 0, 0], + directionMTime: 0, + + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Mapper/index.js b/Sources/Rendering/Core/Mapper/index.js index 595b751c1aa..695e9d7bcdc 100644 --- a/Sources/Rendering/Core/Mapper/index.js +++ b/Sources/Rendering/Core/Mapper/index.js @@ -567,47 +567,50 @@ function vtkMapper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - colorMapColors: null, // Same as this->Colors +function defaultValues(initialValues) { + return { + colorMapColors: null, // Same as this->Colors - static: false, - lookupTable: null, + static: false, + lookupTable: null, - scalarVisibility: true, - scalarRange: [0, 1], - useLookupTableScalarRange: false, + scalarVisibility: true, + scalarRange: [0, 1], + useLookupTableScalarRange: false, - colorMode: 0, - scalarMode: 0, - arrayAccessMode: 1, // By_NAME + colorMode: 0, + scalarMode: 0, + arrayAccessMode: 1, // By_NAME - renderTime: 0, + renderTime: 0, - colorByArrayName: null, + colorByArrayName: null, - fieldDataTupleId: -1, + fieldDataTupleId: -1, - populateSelectionSettings: true, - selectionWebGLIdsToVTKIds: null, + populateSelectionSettings: true, + selectionWebGLIdsToVTKIds: null, - interpolateScalarsBeforeMapping: false, - colorCoordinates: null, - colorTextureMap: null, + interpolateScalarsBeforeMapping: false, + colorCoordinates: null, + colorTextureMap: null, - forceCompileOnly: 0, + forceCompileOnly: 0, - useInvertibleColors: false, - invertibleScalars: null, + useInvertibleColors: false, + invertibleScalars: null, - viewSpecificProperties: null, + viewSpecificProperties: null, - customShaderAttributes: [], -}; + customShaderAttributes: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkAbstractMapper3D.extend(publicAPI, model, initialValues); @@ -636,8 +639,8 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.setGetArray(publicAPI, model, ['scalarRange'], 2); - if (!model.viewSpecificProperties) { - model.viewSpecificProperties = {}; + if (!initialValues.viewSpecificProperties) { + initialValues.viewSpecificProperties = {}; } CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model); diff --git a/Sources/Rendering/Core/Mapper2D/index.js b/Sources/Rendering/Core/Mapper2D/index.js index 51b3b8e8817..f34bd941c18 100644 --- a/Sources/Rendering/Core/Mapper2D/index.js +++ b/Sources/Rendering/Core/Mapper2D/index.js @@ -147,31 +147,34 @@ function vtkMapper2D(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - static: false, - lookupTable: null, +function defaultValues(initialValues) { + return { + static: false, + lookupTable: null, - scalarVisibility: false, - scalarRange: [0, 1], - useLookupTableScalarRange: false, + scalarVisibility: false, + scalarRange: [0, 1], + useLookupTableScalarRange: false, - colorMode: 0, - scalarMode: 0, - arrayAccessMode: 1, // By_NAME + colorMode: 0, + scalarMode: 0, + arrayAccessMode: 1, // By_NAME - renderTime: 0, + renderTime: 0, - colorByArrayName: null, + colorByArrayName: null, - transformCoordinate: null, + transformCoordinate: null, - viewSpecificProperties: null, - customShaderAttributes: [], -}; + viewSpecificProperties: null, + customShaderAttributes: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkAbstractMapper.extend(publicAPI, model, initialValues); @@ -193,8 +196,8 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.setGetArray(publicAPI, model, ['scalarRange'], 2); - if (!model.viewSpecificProperties) { - model.viewSpecificProperties = {}; + if (!initialValues.viewSpecificProperties) { + initialValues.viewSpecificProperties = {}; } // Object methods diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index adf084d8d16..44f8f53f294 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -208,6 +208,10 @@ export function extend(publicAPI, model, initialValues = {}) { model.rotation = mat4.identity(new Float64Array(16)); model.userMatrix = mat4.identity(new Float64Array(16)); model.transform = null; // FIXME + delete initialValues.matrix; + delete initialValues.rotation; + delete initialValues.userMatrix; + delete initialValues.transform; // Object methods vtkProp3D(publicAPI, model); diff --git a/Sources/Rendering/Core/Property/index.js b/Sources/Rendering/Core/Property/index.js index 5ca740532ea..c3c9f7708c3 100644 --- a/Sources/Rendering/Core/Property/index.js +++ b/Sources/Rendering/Core/Property/index.js @@ -16,6 +16,9 @@ function vtkProperty(publicAPI, model) { model.classHierarchy.push('vtkProperty'); publicAPI.setColor = (r, g, b) => { + if (!model.color) { + model.color = [0, 0, 0]; + } if (Array.isArray(r)) { if ( model.color[0] !== r[0] || @@ -87,35 +90,38 @@ function vtkProperty(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - color: [1, 1, 1], - ambientColor: [1, 1, 1], - diffuseColor: [1, 1, 1], - specularColor: [1, 1, 1], - edgeColor: [0, 0, 0], - - ambient: 0, - diffuse: 1, - specular: 0, - specularPower: 1, - opacity: 1, - interpolation: Interpolation.GOURAUD, - representation: Representation.SURFACE, - edgeVisibility: false, - backfaceCulling: false, - frontfaceCulling: false, - pointSize: 1, - lineWidth: 1, - lighting: true, - - shading: false, - materialName: null, -}; +function defaultValues(initialValues) { + return { + color: [1, 1, 1], + ambientColor: [1, 1, 1], + diffuseColor: [1, 1, 1], + specularColor: [1, 1, 1], + edgeColor: [0, 0, 0], + + ambient: 0, + diffuse: 1, + specular: 0, + specularPower: 1, + opacity: 1, + interpolation: Interpolation.GOURAUD, + representation: Representation.SURFACE, + edgeVisibility: false, + backfaceCulling: false, + frontfaceCulling: false, + pointSize: 1, + lineWidth: 1, + lighting: true, + + shading: false, + materialName: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Property2D/index.js b/Sources/Rendering/Core/Property2D/index.js index 6a62a8c247b..2d7b04b09c9 100644 --- a/Sources/Rendering/Core/Property2D/index.js +++ b/Sources/Rendering/Core/Property2D/index.js @@ -31,19 +31,22 @@ function vtkProperty2D(publicAPI, model) { // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - color: [1, 1, 1], - opacity: 1, - pointSize: 1, - lineWidth: 1, - representation: Representation.SURFACE, - displayLocation: DisplayLocation.FOREGROUND, -}; +function defaultValues(initialValues) { + return { + color: [1, 1, 1], + opacity: 1, + pointSize: 1, + lineWidth: 1, + representation: Representation.SURFACE, + displayLocation: DisplayLocation.FOREGROUND, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index f922fe0d0c9..80d93cef2dc 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -137,19 +137,22 @@ function vtkRenderWindow(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - defaultViewAPI: DEFAULT_VIEW_API, - renderers: [], - views: [], - interactor: null, - neverRendered: true, - numberOfLayers: 1, -}; +function defaultValues(initialValues) { + return { + defaultViewAPI: DEFAULT_VIEW_API, + renderers: [], + views: [], + interactor: null, + neverRendered: true, + numberOfLayers: 1, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/Core/Renderer/index.js b/Sources/Rendering/Core/Renderer/index.js index 7ee31f160c3..08d63b9b88d 100644 --- a/Sources/Rendering/Core/Renderer/index.js +++ b/Sources/Rendering/Core/Renderer/index.js @@ -563,75 +563,79 @@ function vtkRenderer(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - pickedProp: null, - activeCamera: null, +function defaultValues(initialValues) { + return { + pickedProp: null, + activeCamera: null, - allBounds: [], - ambient: [1, 1, 1], + allBounds: [], + ambient: [1, 1, 1], - allocatedRenderTime: 100, - timeFactor: 1, + allocatedRenderTime: 100, + timeFactor: 1, - automaticLightCreation: true, + automaticLightCreation: true, - twoSidedLighting: true, - lastRenderTimeInSeconds: -1, + twoSidedLighting: true, + lastRenderTimeInSeconds: -1, - renderWindow: null, - lights: [], - actors: [], - volumes: [], + _renderWindow: null, + lights: [], + actors: [], + volumes: [], - lightFollowCamera: true, + lightFollowCamera: true, - numberOfPropsRendered: 0, + numberOfPropsRendered: 0, - propArray: null, + propArray: null, - pathArray: null, + pathArray: null, - layer: 0, - preserveColorBuffer: false, - preserveDepthBuffer: false, + layer: 0, + preserveColorBuffer: false, + preserveDepthBuffer: false, - computeVisiblePropBounds: vtkMath.createUninitializedBounds(), + computeVisiblePropBounds: vtkMath.createUninitializedBounds(), - interactive: true, + interactive: true, - nearClippingPlaneTolerance: 0, - clippingRangeExpansion: 0.05, + nearClippingPlaneTolerance: 0, + clippingRangeExpansion: 0.05, - erase: true, - draw: true, + erase: true, + draw: true, - useShadows: false, + useShadows: false, - useDepthPeeling: false, - occlusionRatio: 0, - maximumNumberOfPeels: 4, + useDepthPeeling: false, + occlusionRatio: 0, + maximumNumberOfPeels: 4, - selector: null, - delegate: null, + selector: null, + delegate: null, - texturedBackground: false, - backgroundTexture: null, + texturedBackground: false, + backgroundTexture: null, - pass: 0, -}; + pass: 0, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, ['renderWindow']); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewport.extend(publicAPI, model, initialValues); // make sure background has 4 entries. Default to opaque black - if (!model.background) model.background = [0, 0, 0, 1]; - while (model.background.length < 3) model.background.push(0); - if (model.background.length === 3) model.background.push(1); + 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); // Build VTK API macro.get(publicAPI, model, [ @@ -670,7 +674,6 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.getArray(publicAPI, model, ['actors', 'volumes', 'lights']); macro.setGetArray(publicAPI, model, ['background'], 4, 1.0); - macro.moveToProtected(publicAPI, model, ['renderWindow']); // Object methods vtkRenderer(publicAPI, model); diff --git a/Sources/Rendering/Core/Viewport/index.js b/Sources/Rendering/Core/Viewport/index.js index d8b1caf5f8a..139923e410f 100644 --- a/Sources/Rendering/Core/Viewport/index.js +++ b/Sources/Rendering/Core/Viewport/index.js @@ -138,22 +138,25 @@ function vtkViewport(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - // _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: [], -}; +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 = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/OpenGL/Actor2D/index.js b/Sources/Rendering/OpenGL/Actor2D/index.js index 849dc50a94b..613d1ab4dbe 100644 --- a/Sources/Rendering/OpenGL/Actor2D/index.js +++ b/Sources/Rendering/OpenGL/Actor2D/index.js @@ -167,15 +167,18 @@ function vtkOpenGLActor2D(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - context: null, - activeTextures: null, -}; +function defaultValues(initialValues) { + return { + context: null, + activeTextures: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/OpenGL/Camera/index.js b/Sources/Rendering/OpenGL/Camera/index.js index 2a4283f1fc5..1d70ee0937d 100644 --- a/Sources/Rendering/OpenGL/Camera/index.js +++ b/Sources/Rendering/OpenGL/Camera/index.js @@ -88,17 +88,18 @@ function vtkOpenGLCamera(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - context: null, - lastRenderer: null, - keyMatrixTime: null, - keyMatrices: null, -}; +function defaultValues(initialValues) { + return { + context: null, + lastRenderer: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); @@ -107,7 +108,7 @@ export function extend(publicAPI, model, initialValues = {}) { macro.obj(model.keyMatrixTime); // values always get set by the get method - model.keyMatrices = { + initialValues.keyMatrices = { normalMatrix: new Float64Array(9), vcpc: new Float64Array(16), wcvc: new Float64Array(16), diff --git a/Sources/Rendering/OpenGL/Shader/index.js b/Sources/Rendering/OpenGL/Shader/index.js index 21e132cefae..f767ba237d0 100644 --- a/Sources/Rendering/OpenGL/Shader/index.js +++ b/Sources/Rendering/OpenGL/Shader/index.js @@ -76,19 +76,22 @@ function vtkShader(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - shaderType: 'Unknown', - source: '', - error: '', - handle: 0, - dirty: false, - context: null, -}; +function defaultValues(initialValues) { + return { + shaderType: 'Unknown', + source: '', + error: '', + handle: 0, + dirty: false, + context: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/OpenGL/ShaderCache/index.js b/Sources/Rendering/OpenGL/ShaderCache/index.js index 938f96164a4..87fb326f4f9 100644 --- a/Sources/Rendering/OpenGL/ShaderCache/index.js +++ b/Sources/Rendering/OpenGL/ShaderCache/index.js @@ -234,25 +234,27 @@ function vtkShaderCache(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - lastShaderBound: null, - shaderPrograms: null, - context: null, - // _openGLRenderWindow: null, -}; +function defaultValues(initialValues) { + return { + lastShaderBound: null, + context: null, + // _openGLRenderWindow: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + macro.moveToProtected(publicAPI, initialValues, ['openGLRenderWindow']); + Object.assign(initialValues, defaultValues(initialValues)); // Internal objects - model.shaderPrograms = {}; + initialValues.shaderPrograms = {}; // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, SET_GET_FIELDS); - macro.moveToProtected(publicAPI, model, ['openGLRenderWindow']); // Object methods vtkShaderCache(publicAPI, model); diff --git a/Sources/Rendering/OpenGL/ShaderProgram/index.js b/Sources/Rendering/OpenGL/ShaderProgram/index.js index 734ee36d660..9017ac825b7 100644 --- a/Sources/Rendering/OpenGL/ShaderProgram/index.js +++ b/Sources/Rendering/OpenGL/ShaderProgram/index.js @@ -97,12 +97,6 @@ function vtkShaderProgram(publicAPI, model) { publicAPI.setBound(false); }; - publicAPI.setContext = (ctx) => { - model.vertexShader.setContext(ctx); - model.fragmentShader.setContext(ctx); - model.geometryShader.setContext(ctx); - }; - publicAPI.link = () => { if (model.inked) { return true; @@ -516,6 +510,7 @@ function vtkShaderProgram(publicAPI, model) { publicAPI.setContext = (ctx) => { model.context = ctx; + if (!ctx) return; model.vertexShader.setContext(ctx); model.fragmentShader.setContext(ctx); model.geometryShader.setContext(ctx); @@ -550,31 +545,31 @@ function vtkShaderProgram(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - vertexShaderHandle: 0, - fragmentShaderHandle: 0, - geometryShaderHandle: 0, - vertexShader: null, - fragmentShader: null, - geometryShader: null, - - linked: false, - bound: false, - compiled: false, - error: '', - handle: 0, - numberOfOutputs: 0, - attributesLocs: null, - uniformLocs: null, - md5Hash: 0, - context: null, - lastCameraMTime: null, -}; +function defaultValues(initialValues) { + return { + vertexShaderHandle: 0, + fragmentShaderHandle: 0, + geometryShaderHandle: 0, + + linked: false, + bound: false, + compiled: false, + error: '', + handle: 0, + numberOfOutputs: 0, + attributesLocs: null, + uniformLocs: null, + md5Hash: 0, + context: null, + lastCameraMTime: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Instantiate internal objects model.attributesLocs = {}; diff --git a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js index c72cbc1b9eb..941bc32488b 100644 --- a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js +++ b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js @@ -20,15 +20,17 @@ function vtkOpenGLViewNodeFactory(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = {}; +function defaultValues(initialValues) { + return { ...initialValues }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Static class mapping shared across instances - model.overrides = CLASS_MAPPING; + initialValues.overrides = CLASS_MAPPING; // Inheritance vtkViewNodeFactory.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/WebGPU/Camera/index.js b/Sources/Rendering/WebGPU/Camera/index.js index d44af44a855..5b990faebbe 100644 --- a/Sources/Rendering/WebGPU/Camera/index.js +++ b/Sources/Rendering/WebGPU/Camera/index.js @@ -131,24 +131,27 @@ function vtkWebGPUCamera(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - keyMatrixTime: null, - keyMatrices: null, -}; +function defaultValues(initialValues) { + return { + keyMatrixTime: null, + keyMatrices: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.keyMatrixTime = {}; - macro.obj(model.keyMatrixTime); + initialValues.keyMatrixTime = {}; + macro.obj(initialValues.keyMatrixTime); // values always get set by the get method - model.keyMatrices = { + initialValues.keyMatrices = { normalMatrix: new Float64Array(16), vcpc: new Float64Array(16), pcsc: new Float64Array(16), diff --git a/Sources/Rendering/WebGPU/RenderWindow/index.js b/Sources/Rendering/WebGPU/RenderWindow/index.js index 97224805820..2846a2be2e0 100644 --- a/Sources/Rendering/WebGPU/RenderWindow/index.js +++ b/Sources/Rendering/WebGPU/RenderWindow/index.js @@ -548,28 +548,31 @@ function vtkWebGPURenderWindow(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - initialized: false, - context: null, - adapter: null, - device: null, - canvas: null, - cursorVisibility: true, - cursor: 'pointer', - containerSize: null, - renderPasses: [], - notifyStartCaptureImage: false, - imageFormat: 'image/png', - useOffScreen: false, - useBackgroundImage: false, - nextPropID: 1, - xrSupported: false, -}; +function defaultValues(initialValues) { + return { + initialized: false, + context: null, + adapter: null, + device: null, + canvas: null, + cursorVisibility: true, + cursor: 'pointer', + containerSize: null, + renderPasses: [], + notifyStartCaptureImage: false, + imageFormat: 'image/png', + useOffScreen: false, + useBackgroundImage: false, + nextPropID: 1, + xrSupported: false, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Create internal instances model.canvas = document.createElement('canvas'); @@ -577,6 +580,7 @@ export function extend(publicAPI, model, initialValues = {}) { // Create internal bgImage model.bgImage = new Image(); + delete initialValues.bgImage; model.bgImage.style.position = 'absolute'; model.bgImage.style.left = '0'; model.bgImage.style.top = '0'; @@ -595,9 +599,9 @@ export function extend(publicAPI, model, initialValues = {}) { // setup default forward pass rendering model.renderPasses[0] = vtkForwardPass.newInstance(); - if (!model.selector) { - model.selector = vtkWebGPUHardwareSelector.newInstance(); - model.selector.setWebGPURenderWindow(publicAPI); + if (!initialValues.selector) { + initialValues.selector = vtkWebGPUHardwareSelector.newInstance(); + initialValues.selector.setWebGPURenderWindow(publicAPI); } macro.event(publicAPI, model, 'imageReady'); diff --git a/Sources/Rendering/WebGPU/Renderer/index.js b/Sources/Rendering/WebGPU/Renderer/index.js index cefca9a1c31..ed285fd1e25 100644 --- a/Sources/Rendering/WebGPU/Renderer/index.js +++ b/Sources/Rendering/WebGPU/Renderer/index.js @@ -314,19 +314,22 @@ function vtkWebGPURenderer(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - bindGroup: null, - selector: null, - renderEncoder: null, - recenterThreshold: 20.0, - suppressClear: false, - stabilizedCenter: [0.0, 0.0, 0.0], -}; +function defaultValues(initialValues) { + return { + bindGroup: null, + selector: null, + renderEncoder: null, + recenterThreshold: 20.0, + suppressClear: false, + stabilizedCenter: [0.0, 0.0, 0.0], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/WebGPU/ShaderCache/index.js b/Sources/Rendering/WebGPU/ShaderCache/index.js index ef19b82835b..1d9fdce769e 100644 --- a/Sources/Rendering/WebGPU/ShaderCache/index.js +++ b/Sources/Rendering/WebGPU/ShaderCache/index.js @@ -52,16 +52,19 @@ function vtkWebGPUShaderCache(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - shaderModules: null, - device: null, - window: null, -}; +function defaultValues(initialValues) { + return { + shaderModules: null, + device: null, + window: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Internal objects model._shaderModules = new Map(); diff --git a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js index 0cb5dff6695..db4ffca4445 100644 --- a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js +++ b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js @@ -20,12 +20,14 @@ function vtkWebGPUViewNodeFactory(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = {}; +function defaultValues(initialValues) { + return { ...initialValues }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Static class mapping shared across instances model.overrides = CLASS_MAPPING; From 787a134a89e375380f3ff65e449affe52568795d Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 8 Jun 2022 10:32:52 +0200 Subject: [PATCH 05/36] fix(abstractmapper): fix setClippingPlane at instanciation fix setClippingPlane at instanciation. Handle [] as possible given planes. --- Sources/Rendering/Core/AbstractMapper/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Rendering/Core/AbstractMapper/index.js b/Sources/Rendering/Core/AbstractMapper/index.js index c1f05c69325..13330adc0d9 100644 --- a/Sources/Rendering/Core/AbstractMapper/index.js +++ b/Sources/Rendering/Core/AbstractMapper/index.js @@ -42,7 +42,8 @@ function vtkAbstractMapper(publicAPI, model) { publicAPI.getClippingPlanes = () => model.clippingPlanes; publicAPI.setClippingPlanes = (planes) => { - if (!planes) { + if (!planes || planes.length === 0) { + model.clippingPlanes = []; return; } if (!Array.isArray(planes)) { From 592e0e0aa9492defe0b8e9ce7cbbd6ce3fb40eac Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 8 Jun 2022 17:54:43 +0200 Subject: [PATCH 06/36] fix(actor,actor2d): fix refactoring fix --- Sources/Common/Core/LookupTable/index.js | 15 ++--- Sources/Rendering/Core/Actor/index.js | 45 +++++++------- Sources/Rendering/Core/Actor2D/index.js | 26 ++++---- Sources/Rendering/Core/Camera/index.js | 9 ++- Sources/Rendering/Core/Prop3D/index.js | 59 ++++++++----------- Sources/Rendering/OpenGL/Actor/index.js | 39 ++++++------ Sources/Rendering/OpenGL/Camera/index.js | 19 +++--- Sources/Rendering/OpenGL/Renderer/index.js | 26 ++++---- .../Rendering/OpenGL/ShaderProgram/index.js | 20 +++---- .../SceneGraph/RenderWindowViewNode/index.js | 22 +++---- .../Rendering/SceneGraph/ViewNode/index.js | 33 +++++------ Sources/Rendering/WebGPU/Camera/index.js | 25 ++++---- Sources/Rendering/WebGPU/Renderer/index.js | 33 +++++------ 13 files changed, 176 insertions(+), 195 deletions(-) diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index 04534165723..f59828b8da5 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -302,8 +302,12 @@ function vtkLookupTable(publicAPI, model) { function defaultValues(initialValues) { return { + // Internal objects + buildTime: macro.obj({}), + opaqueFlagBuildTime: macro.obj({}, { mtime: 0 }), + insertTime: macro.obj({}, { mtime: 0 }), + numberOfColors: 256, - // table: null, hueRange: [0.0, 0.66667], saturationRange: [1.0, 1.0], @@ -337,15 +341,6 @@ export function extend(publicAPI, model, initialValues = {}) { model.table = []; } - model.buildTime = {}; - macro.obj(model.buildTime); - - model.opaqueFlagBuildTime = {}; - macro.obj(model.opaqueFlagBuildTime, { mtime: 0 }); - - model.insertTime = {}; - macro.obj(model.insertTime, { mtime: 0 }); - // Create get-only macros macro.get(publicAPI, model, ['buildTime']); diff --git a/Sources/Rendering/Core/Actor/index.js b/Sources/Rendering/Core/Actor/index.js index d080dc48b7f..3be372fe188 100644 --- a/Sources/Rendering/Core/Actor/index.js +++ b/Sources/Rendering/Core/Actor/index.js @@ -6,25 +6,6 @@ import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property'; const { vtkDebugMacro } = macro; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - mapper: null, - property: null, - backfaceProperty: null, - - forceOpaque: false, - forceTranslucent: false, - - bounds: [1, -1, 1, -1, 1, -1], - - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkActor methods // ---------------------------------------------------------------------------- @@ -185,6 +166,28 @@ function vtkActor(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal objects + boundsMTime: macro.obj({}), + + mapper: null, + property: null, + backfaceProperty: null, + + forceOpaque: false, + forceTranslucent: false, + + bounds: [1, -1, 1, -1, 1, -1], + + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -193,10 +196,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkProp3D.extend(publicAPI, model, initialValues); - // vtkTimeStamp - model.boundsMTime = {}; - macro.obj(model.boundsMTime); - // Build VTK API macro.set(publicAPI, model, ['property']); macro.setGet(publicAPI, model, [ diff --git a/Sources/Rendering/Core/Actor2D/index.js b/Sources/Rendering/Core/Actor2D/index.js index ee9b3b3cde2..7a143090488 100644 --- a/Sources/Rendering/Core/Actor2D/index.js +++ b/Sources/Rendering/Core/Actor2D/index.js @@ -4,19 +4,6 @@ import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop'; import vtkProperty2D from 'vtk.js/Sources/Rendering/Core/Property2D'; import { Coordinate } from 'vtk.js/Sources/Rendering/Core/Coordinate/Constants'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - mapper: null, - property: null, - layerNumber: 0, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkActor2D methods // ---------------------------------------------------------------------------- @@ -146,6 +133,19 @@ function vtkActor2D(publicAPI, model) { publicAPI.getActualPositionCoordinate2 = () => model.positionCoordinate2; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + mapper: null, + property: null, + layerNumber: 0, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/Core/Camera/index.js b/Sources/Rendering/Core/Camera/index.js index eb4b1520d32..751832f24e7 100644 --- a/Sources/Rendering/Core/Camera/index.js +++ b/Sources/Rendering/Core/Camera/index.js @@ -233,6 +233,7 @@ function vtkCamera(publicAPI, model) { ); vec4.transformMat4(viewUpVec4, viewUpVec4, rotateMatrix); + if (!model.viewUp) model.viewUp = defaultValues().viewUp; model.viewUp[0] = viewUpVec4[0]; model.viewUp[1] = viewUpVec4[1]; model.viewUp[2] = viewUpVec4[2]; @@ -241,7 +242,7 @@ function vtkCamera(publicAPI, model) { }; publicAPI.azimuth = (angle) => { - const fp = model.focalPoint; + const fp = model.focalPoint ? model.focalPoint : defaultValues().focalPoint; mat4.identity(trans); @@ -249,11 +250,13 @@ function vtkCamera(publicAPI, model) { // rotate about view up, // translate back again mat4.translate(trans, trans, fp); - mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), model.viewUp); + const viewUp = model.viewUp ? model.viewUp : defaultValues().viewUp; + mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), viewUp); mat4.translate(trans, trans, [-fp[0], -fp[1], -fp[2]]); // apply the transform to the position - vec3.transformMat4(newPosition, model.position, trans); + const pos = model.position ? model.position : defaultValues().position; + vec3.transformMat4(newPosition, pos, trans); publicAPI.setPosition(newPosition[0], newPosition[1], newPosition[2]); }; diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index 44f8f53f294..b17ac42bb5b 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -5,26 +5,6 @@ import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox'; import * as vtkMath from 'vtk.js/Sources/Common/Core/Math'; import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - origin: [0, 0, 0], - position: [0, 0, 0], - orientation: [0, 0, 0], - scale: [1, 1, 1], - bounds: [1, -1, 1, -1, 1, -1], - - userMatrixMTime: null, - - cachedProp3D: null, - isIdentity: true, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkProp3D methods // ---------------------------------------------------------------------------- @@ -187,6 +167,32 @@ function vtkProp3D(publicAPI, model) { publicAPI.onModified(updateIdentityFlag); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + origin: [0, 0, 0], + position: [0, 0, 0], + orientation: [0, 0, 0], + scale: [1, 1, 1], + bounds: [1, -1, 1, -1, 1, -1], + + matrix: mat4.identity(new Float64Array(16)), + rotation: mat4.identity(new Float64Array(16)), + userMatrix: mat4.identity(new Float64Array(16)), + transform: null, + matrixMTime: macro.obj({}), + + userMatrixMTime: null, + + cachedProp3D: null, + isIdentity: true, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -195,24 +201,11 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkProp.extend(publicAPI, model, initialValues); - model.matrixMTime = {}; - macro.obj(model.matrixMTime); - // Build VTK API macro.get(publicAPI, model, ['bounds', 'isIdentity']); macro.getArray(publicAPI, model, ['orientation']); macro.setGetArray(publicAPI, model, ['origin', 'position', 'scale'], 3); - // Object internal instance - model.matrix = mat4.identity(new Float64Array(16)); - model.rotation = mat4.identity(new Float64Array(16)); - model.userMatrix = mat4.identity(new Float64Array(16)); - model.transform = null; // FIXME - delete initialValues.matrix; - delete initialValues.rotation; - delete initialValues.userMatrix; - delete initialValues.transform; - // Object methods vtkProp3D(publicAPI, model); } diff --git a/Sources/Rendering/OpenGL/Actor/index.js b/Sources/Rendering/OpenGL/Actor/index.js index c00d638d1ef..874830eaee3 100644 --- a/Sources/Rendering/OpenGL/Actor/index.js +++ b/Sources/Rendering/OpenGL/Actor/index.js @@ -5,18 +5,6 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - context: null, - activeTextures: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkOpenGLActor methods // ---------------------------------------------------------------------------- @@ -192,6 +180,26 @@ function vtkOpenGLActor(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal objects + keyMatrixTime: macro.obj({}, { mtime: 0 }), + keyMatrices: { + normalMatrix: mat3.identity(new Float64Array(9)), + mcwc: mat4.identity(new Float64Array(16)), + }, + + context: null, + activeTextures: null, + + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -200,13 +208,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - initialValues.keyMatrixTime = {}; - macro.obj(initialValues.keyMatrixTime, { mtime: 0 }); - initialValues.keyMatrices = { - normalMatrix: mat3.identity(new Float64Array(9)), - mcwc: mat4.identity(new Float64Array(16)), - }; - // Build VTK API macro.setGet(publicAPI, model, ['context']); diff --git a/Sources/Rendering/OpenGL/Camera/index.js b/Sources/Rendering/OpenGL/Camera/index.js index 1d70ee0937d..e372fd38b3b 100644 --- a/Sources/Rendering/OpenGL/Camera/index.js +++ b/Sources/Rendering/OpenGL/Camera/index.js @@ -92,6 +92,14 @@ function defaultValues(initialValues) { return { context: null, lastRenderer: null, + keyMatrixTime: macro.obj({}), + // values always get set by the get method + keyMatrices: { + normalMatrix: new Float64Array(9), + vcpc: new Float64Array(16), + wcvc: new Float64Array(16), + wcpc: new Float64Array(16), + }, ...initialValues, }; } @@ -104,17 +112,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.keyMatrixTime = {}; - macro.obj(model.keyMatrixTime); - - // values always get set by the get method - initialValues.keyMatrices = { - normalMatrix: new Float64Array(9), - vcpc: new Float64Array(16), - wcvc: new Float64Array(16), - wcpc: new Float64Array(16), - }; - // Build VTK API macro.setGet(publicAPI, model, ['context', 'keyMatrixTime']); diff --git a/Sources/Rendering/OpenGL/Renderer/index.js b/Sources/Rendering/OpenGL/Renderer/index.js index ad36e4b30dc..cea59058cc5 100644 --- a/Sources/Rendering/OpenGL/Renderer/index.js +++ b/Sources/Rendering/OpenGL/Renderer/index.js @@ -5,19 +5,6 @@ import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactor const { vtkDebugMacro } = macro; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - context: null, - // _openGLRenderWindow: null, - selector: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkOpenGLRenderer methods // ---------------------------------------------------------------------------- @@ -197,6 +184,19 @@ function vtkOpenGLRenderer(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + context: null, + // _openGLRenderWindow: null, + selector: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/OpenGL/ShaderProgram/index.js b/Sources/Rendering/OpenGL/ShaderProgram/index.js index 9017ac825b7..4a871126c54 100644 --- a/Sources/Rendering/OpenGL/ShaderProgram/index.js +++ b/Sources/Rendering/OpenGL/ShaderProgram/index.js @@ -551,14 +551,19 @@ function defaultValues(initialValues) { fragmentShaderHandle: 0, geometryShaderHandle: 0, + // Internal objects + vertexShader: vtkShader.newInstance(), + fragmentShader: vtkShader.newInstance(), + geometryShader: vtkShader.newInstance(), + linked: false, bound: false, compiled: false, error: '', handle: 0, numberOfOutputs: 0, - attributesLocs: null, - uniformLocs: null, + attributesLocs: {}, + uniformLocs: {}, md5Hash: 0, context: null, lastCameraMTime: null, @@ -572,14 +577,9 @@ function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); // Instantiate internal objects - model.attributesLocs = {}; - model.uniformLocs = {}; - model.vertexShader = vtkShader.newInstance(); - model.vertexShader.setShaderType('Vertex'); - model.fragmentShader = vtkShader.newInstance(); - model.fragmentShader.setShaderType('Fragment'); - model.geometryShader = vtkShader.newInstance(); - model.geometryShader.setShaderType('Geometry'); + initialValues.vertexShader.setShaderType('Vertex'); + initialValues.fragmentShader.setShaderType('Fragment'); + initialValues.geometryShader.setShaderType('Geometry'); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index 25a9c4e15c0..d1853f8845a 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -9,17 +9,6 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; // view try to limit such interactions to methods defined in this class. // ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - selector: undefined, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkRenderWindowViewNode methods // ---------------------------------------------------------------------------- @@ -157,6 +146,17 @@ function vtkRenderWindowViewNode(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + selector: undefined, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/SceneGraph/ViewNode/index.js b/Sources/Rendering/SceneGraph/ViewNode/index.js index a0eff8a2ce4..2688501beda 100644 --- a/Sources/Rendering/SceneGraph/ViewNode/index.js +++ b/Sources/Rendering/SceneGraph/ViewNode/index.js @@ -4,21 +4,6 @@ const { vtkErrorMacro } = macro; const PASS_TYPES = ['Build', 'Render']; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - // _parent: null, - renderable: null, - myFactory: null, - children: [], - visited: false, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkViewNode methods // ---------------------------------------------------------------------------- @@ -201,6 +186,22 @@ function vtkViewNode(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // _parent: null, + renderable: null, + myFactory: null, + children: [], + visited: false, + _renderableChildMap: new Map(), + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- function extend(publicAPI, model, initialValues = {}) { @@ -211,8 +212,6 @@ function extend(publicAPI, model, initialValues = {}) { macro.obj(publicAPI, model); macro.event(publicAPI, model, 'event'); - initialValues._renderableChildMap = new Map(); - macro.get(publicAPI, model, ['visited']); macro.setGet(publicAPI, model, ['_parent', 'renderable', 'myFactory']); macro.getArray(publicAPI, model, ['children']); diff --git a/Sources/Rendering/WebGPU/Camera/index.js b/Sources/Rendering/WebGPU/Camera/index.js index 5b990faebbe..c447c65f05b 100644 --- a/Sources/Rendering/WebGPU/Camera/index.js +++ b/Sources/Rendering/WebGPU/Camera/index.js @@ -133,8 +133,16 @@ function vtkWebGPUCamera(publicAPI, model) { function defaultValues(initialValues) { return { - keyMatrixTime: null, - keyMatrices: null, + keyMatrixTime: macro.obj({}), + // values always get set by the get method + keyMatrices: { + normalMatrix: new Float64Array(16), + vcpc: new Float64Array(16), + pcsc: new Float64Array(16), + wcvc: new Float64Array(16), + scpc: new Float64Array(16), + scvc: new Float64Array(16), + }, ...initialValues, }; } @@ -147,19 +155,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - initialValues.keyMatrixTime = {}; - macro.obj(initialValues.keyMatrixTime); - - // values always get set by the get method - initialValues.keyMatrices = { - normalMatrix: new Float64Array(16), - vcpc: new Float64Array(16), - pcsc: new Float64Array(16), - wcvc: new Float64Array(16), - scpc: new Float64Array(16), - scvc: new Float64Array(16), - }; - // Build VTK API macro.setGet(publicAPI, model, ['keyMatrixTime']); diff --git a/Sources/Rendering/WebGPU/Renderer/index.js b/Sources/Rendering/WebGPU/Renderer/index.js index ed285fd1e25..e3d9097d087 100644 --- a/Sources/Rendering/WebGPU/Renderer/index.js +++ b/Sources/Rendering/WebGPU/Renderer/index.js @@ -316,12 +316,18 @@ function vtkWebGPURenderer(publicAPI, model) { function defaultValues(initialValues) { return { - bindGroup: null, + // Internal objects + UBO: vtkWebGPUUniformBuffer.newInstance({ label: 'rendererUBO' }), + bindGroup: vtkWebGPUBindGroup.newInstance({ label: 'rendererBG' }), + tmpMat4: mat4.identity(new Float64Array(16)), + stabilizedTime: macro.obj({}, { mtime: 0 }), + selector: null, renderEncoder: null, recenterThreshold: 20.0, suppressClear: false, stabilizedCenter: [0.0, 0.0, 0.0], + ...initialValues, }; } @@ -334,23 +340,16 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.UBO = vtkWebGPUUniformBuffer.newInstance({ label: 'rendererUBO' }); - model.UBO.addEntry('WCVCMatrix', 'mat4x4'); - model.UBO.addEntry('SCPCMatrix', 'mat4x4'); - model.UBO.addEntry('PCSCMatrix', 'mat4x4'); - model.UBO.addEntry('SCVCMatrix', 'mat4x4'); - model.UBO.addEntry('VCPCMatrix', 'mat4x4'); - model.UBO.addEntry('WCVCNormals', 'mat4x4'); - model.UBO.addEntry('viewportSize', 'vec2'); - model.UBO.addEntry('cameraParallel', 'u32'); - - model.bindGroup = vtkWebGPUBindGroup.newInstance({ label: 'rendererBG' }); - model.bindGroup.setBindables([model.UBO]); - - model.tmpMat4 = mat4.identity(new Float64Array(16)); + initialValues.UBO.addEntry('WCVCMatrix', 'mat4x4'); + initialValues.UBO.addEntry('SCPCMatrix', 'mat4x4'); + initialValues.UBO.addEntry('PCSCMatrix', 'mat4x4'); + initialValues.UBO.addEntry('SCVCMatrix', 'mat4x4'); + initialValues.UBO.addEntry('VCPCMatrix', 'mat4x4'); + initialValues.UBO.addEntry('WCVCNormals', 'mat4x4'); + initialValues.UBO.addEntry('viewportSize', 'vec2'); + initialValues.UBO.addEntry('cameraParallel', 'u32'); - model.stabilizedTime = {}; - macro.obj(model.stabilizedTime, { mtime: 0 }); + initialValues.bindGroup.setBindables([initialValues.UBO]); // Build VTK API macro.get(publicAPI, model, ['bindGroup', 'stabilizedTime']); From f011c1428c700b224edf664b96143826e6dfc4ae Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Thu, 9 Jun 2022 16:38:45 +0200 Subject: [PATCH 07/36] fix(hardwareselector, renderwindow): fix refactoring change polydatamapper --- Sources/Rendering/Core/RenderWindow/index.js | 33 +++++++------- Sources/Rendering/Core/Viewport/index.js | 38 ++++++++-------- .../OpenGL/HardwareSelector/index.js | 4 ++ .../Rendering/OpenGL/PolyDataMapper/index.js | 43 +++++++++---------- .../WebGPU/HardwareSelector/index.js | 3 +- 5 files changed, 59 insertions(+), 62 deletions(-) diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index 80d93cef2dc..ab094976ae1 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -15,8 +15,21 @@ export function listViewAPIs() { return Object.keys(VIEW_CONSTRUCTORS); } -export function newAPISpecificView(name, initialValues = {}) { - return VIEW_CONSTRUCTORS[name] && VIEW_CONSTRUCTORS[name](initialValues); + +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + defaultViewAPI: DEFAULT_VIEW_API, + renderers: [], + views: [], + interactor: null, + neverRendered: true, + numberOfLayers: 1, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -133,22 +146,6 @@ 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 = {}) { diff --git a/Sources/Rendering/Core/Viewport/index.js b/Sources/Rendering/Core/Viewport/index.js index 139923e410f..9c32fd8ef4a 100644 --- a/Sources/Rendering/Core/Viewport/index.js +++ b/Sources/Rendering/Core/Viewport/index.js @@ -6,6 +6,25 @@ 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 // ---------------------------------------------------------------------------- @@ -134,25 +153,6 @@ 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 = {}) { diff --git a/Sources/Rendering/OpenGL/HardwareSelector/index.js b/Sources/Rendering/OpenGL/HardwareSelector/index.js index 327d5e73cc6..a2dbac1ecd4 100644 --- a/Sources/Rendering/OpenGL/HardwareSelector/index.js +++ b/Sources/Rendering/OpenGL/HardwareSelector/index.js @@ -340,6 +340,10 @@ function defaultValues(initialValues) { // _openGLRenderWindow: null, // _openGLRenderer: null, currentPass: -1, + propColorValue: null, + props: null, + maximumPointId: 0, + maximumCellId: 0, idOffset: 1, ...initialValues, }; diff --git a/Sources/Rendering/OpenGL/PolyDataMapper/index.js b/Sources/Rendering/OpenGL/PolyDataMapper/index.js index 12859d1f2f2..b6778b94378 100755 --- a/Sources/Rendering/OpenGL/PolyDataMapper/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper/index.js @@ -2010,32 +2010,35 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - context: null, - VBOBuildTime: 0, - VBOBuildString: null, - primitives: null, - primTypes: null, - shaderRebuildString: null, - tmpMat4: null, +function defaultValues(initialValues) { + return { ambientColor: [], // used internally diffuseColor: [], // used internally specularColor: [], // used internally lightColor: [], // used internally lightHalfAngle: [], // used internally lightDirection: [], // used internally + VBOBuildTime: macro.obj({}, { mtime: 0 }), + selectionStateChanged: macro.obj({}, { mtime: 0 }), + + context: null, + VBOBuildString: null, + primitives: null, + primTypes: null, + shaderRebuildString: null, + lastHaveSeenDepthRequest: false, haveSeenDepthRequest: false, lastSelectionState: PassTypes.MIN_KNOWN_PASS - 1, - selectionStateChanged: null, selectionWebGLIdsToVTKIds: null, pointPicking: false, }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); @@ -2045,16 +2048,16 @@ export function extend(publicAPI, model, initialValues = {}) { initialValues ); - model.primitives = []; - model.primTypes = primTypes; + initialValues.primitives = []; + initialValues.primTypes = primTypes; - model.tmpMat3 = mat3.identity(new Float64Array(9)); - model.tmpMat4 = mat4.identity(new Float64Array(16)); + initialValues.tmpMat3 = mat3.identity(new Float64Array(9)); + initialValues.tmpMat4 = mat4.identity(new Float64Array(16)); for (let i = primTypes.Start; i < primTypes.End; i++) { - model.primitives[i] = vtkHelper.newInstance(); - model.primitives[i].setPrimitiveType(i); - model.primitives[i].set( + initialValues.primitives[i] = vtkHelper.newInstance(); + initialValues.primitives[i].setPrimitiveType(i); + initialValues.primitives[i].set( { lastLightComplexity: 0, lastLightCount: 0, lastSelectionPass: false }, true ); @@ -2063,12 +2066,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Build VTK API macro.setGet(publicAPI, model, ['context']); - model.VBOBuildTime = {}; - macro.obj(model.VBOBuildTime, { mtime: 0 }); - - model.selectionStateChanged = {}; - macro.obj(model.selectionStateChanged, { mtime: 0 }); - // Object methods vtkOpenGLPolyDataMapper(publicAPI, model); } diff --git a/Sources/Rendering/WebGPU/HardwareSelector/index.js b/Sources/Rendering/WebGPU/HardwareSelector/index.js index 49ae8d54110..b159bf45ac3 100644 --- a/Sources/Rendering/WebGPU/HardwareSelector/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelector/index.js @@ -259,6 +259,7 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { function defaultValues(initialValues) { return { WebGPURenderWindow: null, + _selectionPass: vtkWebGPUHardwareSelectionPass.newInstance(), ...initialValues, }; } @@ -432,8 +433,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Build VTK API vtkHardwareSelector.extend(publicAPI, model, initialValues); - model._selectionPass = vtkWebGPUHardwareSelectionPass.newInstance(); - macro.setGet(publicAPI, model, ['WebGPURenderWindow']); // Object methods From b2d09ed873582c0e2f7d812b9b1fd9c42df0886c Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Thu, 9 Jun 2022 16:50:38 +0200 Subject: [PATCH 08/36] fix(polydatamapper2d): refactor constructor call setters at instanciation --- .../OpenGL/PolyDataMapper2D/index.js | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js index 386e08f98cd..ffce329657d 100644 --- a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js @@ -23,6 +23,24 @@ const { vtkErrorMacro } = macro; const StartEvent = { type: 'StartEvent' }; const EndEvent = { type: 'EndEvent' }; +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal Objects + VBOBuildTime: macro.obj({}, { mtime: 0 }), + VBOBuildString: null, + primitives: null, + primTypes: null, + context: null, + + shaderRebuildString: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkOpenGLPolyDataMapper2D methods // ---------------------------------------------------------------------------- @@ -719,23 +737,10 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - context: null, - VBOBuildTime: 0, - VBOBuildString: null, - primitives: null, - primTypes: null, - shaderRebuildString: null, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); @@ -745,15 +750,15 @@ export function extend(publicAPI, model, initialValues = {}) { initialValues ); - model.primitives = []; - model.primTypes = primTypes; + initialValues.primitives = []; + initialValues.primTypes = primTypes; - model.tmpMat4 = mat4.identity(new Float64Array(16)); + initialValues.tmpMat4 = mat4.identity(new Float64Array(16)); for (let i = primTypes.Start; i < primTypes.End; i++) { - model.primitives[i] = vtkHelper.newInstance(); - model.primitives[i].setPrimitiveType(i); - model.primitives[i].set( + initialValues.primitives[i] = vtkHelper.newInstance(); + initialValues.primitives[i].setPrimitiveType(i); + initialValues.primitives[i].set( { lastLightComplexity: 0, lastLightCount: 0, lastSelectionPass: false }, true ); @@ -762,9 +767,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Build VTK API macro.setGet(publicAPI, model, ['context']); - model.VBOBuildTime = {}; - macro.obj(model.VBOBuildTime, { mtime: 0 }); - // Object methods vtkOpenGLPolyDataMapper2D(publicAPI, model); } From 27e181b3f66602f95d46eaa52e258caad514c144 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Fri, 10 Jun 2022 11:29:20 +0200 Subject: [PATCH 09/36] fix(datasetattributes): refactor constructors refactor DataSetAttributes constructor to call setters --- .../Common/DataModel/DataSetAttributes/FieldData.js | 2 +- Sources/Common/DataModel/DataSetAttributes/index.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index 0ccdb65ed0c..6afdafc9e41 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -67,7 +67,7 @@ function vtkFieldData(publicAPI, model) { : a, { array: null, index: -1 } ) - : null; + : { array: null, index: -1 }; publicAPI.getArrayByIndex = (idx) => idx >= 0 && idx < model.arrays.length ? model.arrays[idx].data : null; publicAPI.hasArray = (arrayName) => { diff --git a/Sources/Common/DataModel/DataSetAttributes/index.js b/Sources/Common/DataModel/DataSetAttributes/index.js index aceec25a9a2..3cef50e2678 100644 --- a/Sources/Common/DataModel/DataSetAttributes/index.js +++ b/Sources/Common/DataModel/DataSetAttributes/index.js @@ -234,7 +234,8 @@ function vtkDataSetAttributes(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { +function defaultValues(initialValues) { + return { activeScalars: -1, activeVectors: -1, activeTensors: -1, @@ -242,12 +243,14 @@ const DEFAULT_VALUES = { activeTCoords: -1, activeGlobalIds: -1, activePedigreeIds: -1, + ...initialValues, }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods vtkFieldData.extend(publicAPI, model, initialValues); @@ -261,8 +264,8 @@ export function extend(publicAPI, model, initialValues = {}) { 'activePedigreeIds', ]); - if (!model.arrays) { - model.arrays = {}; + if (!initialValues.arrays) { + initialValues.arrays = {}; } // Object specific methods From c1f6ef65459d4fc73f2b62c57299fd47a6e71053 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Mon, 13 Jun 2022 10:07:28 +0200 Subject: [PATCH 10/36] fix(colortransferfunction): refactor constructor to call setters update setActiveProperty of datasetattributes to handle indexes being given --- Sources/Common/Core/ScalarsToColors/index.js | 29 ++++----- .../DataModel/DataSetAttributes/index.js | 15 +++-- .../Core/ColorTransferFunction/index.js | 65 +++++++++---------- 3 files changed, 54 insertions(+), 55 deletions(-) diff --git a/Sources/Common/Core/ScalarsToColors/index.js b/Sources/Common/Core/ScalarsToColors/index.js index ef5aaf07cd3..8a20aac7955 100644 --- a/Sources/Common/Core/ScalarsToColors/index.js +++ b/Sources/Common/Core/ScalarsToColors/index.js @@ -517,29 +517,28 @@ function vtkScalarsToColors(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - alpha: 1.0, - vectorComponent: 0, - vectorSize: -1, - vectorMode: VectorMode.COMPONENT, - mappingRange: null, - annotationArray: null, - annotatedValueMap: null, - indexedLookup: false, -}; +function defaultValues(initialValues) { + return { + alpha: 1.0, + vectorComponent: 0, + vectorSize: -1, + vectorMode: VectorMode.COMPONENT, + mappingRange: [0, 255], + annotationArray: [], + annotatedValueMap: [], + indexedLookup: false, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); - model.mappingRange = [0, 255]; - model.annotationArray = []; - model.annotatedValueMap = []; - // Create get-set macros macro.setGet(publicAPI, model, [ 'vectorSize', diff --git a/Sources/Common/DataModel/DataSetAttributes/index.js b/Sources/Common/DataModel/DataSetAttributes/index.js index 3cef50e2678..933a1cedcf8 100644 --- a/Sources/Common/DataModel/DataSetAttributes/index.js +++ b/Sources/Common/DataModel/DataSetAttributes/index.js @@ -161,11 +161,14 @@ function vtkDataSetAttributes(publicAPI, model) { publicAPI[`get${value}`] = () => publicAPI.getArrayByIndex(model[activeVal]); publicAPI[`set${value}`] = (da) => publicAPI.setAttribute(da, value); - publicAPI[`setActive${value}`] = (arrayName) => - publicAPI.setActiveAttributeByIndex( - publicAPI.getArrayWithIndex(arrayName).index, + publicAPI[`setActive${value}`] = (arrayNameOrIndex) => { + if (typeof arrayNameOrIndex === 'number') + return publicAPI.setActiveAttributeByIndex(arrayNameOrIndex, value); + return publicAPI.setActiveAttributeByIndex( + publicAPI.getArrayWithIndex(arrayNameOrIndex).index, value ); + }; publicAPI[`copy${value}Off`] = () => { const attType = value.toUpperCase(); model.copyAttributeFlags[AttributeCopyOperations.PASSDATA][ @@ -264,9 +267,9 @@ export function extend(publicAPI, model, initialValues = {}) { 'activePedigreeIds', ]); - if (!initialValues.arrays) { - initialValues.arrays = {}; - } + // model.arrays must exist before calling setActiveAttribute + model.arrays = initialValues.arrays; + delete initialValues.arrays; // Object specific methods vtkDataSetAttributes(publicAPI, model); diff --git a/Sources/Rendering/Core/ColorTransferFunction/index.js b/Sources/Rendering/Core/ColorTransferFunction/index.js index 5287da2cc91..97f893a2507 100644 --- a/Sources/Rendering/Core/ColorTransferFunction/index.js +++ b/Sources/Rendering/Core/ColorTransferFunction/index.js @@ -1197,48 +1197,45 @@ function vtkColorTransferFunction(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - clamping: true, - colorSpace: ColorSpace.RGB, - hSVWrap: true, - scale: Scale.LINEAR, - - nanColor: null, - belowRangeColor: null, - aboveRangeColor: null, - useAboveRangeColor: false, - useBelowRangeColor: false, - - allowDuplicateScalars: false, - - table: null, - tableSize: 0, - buildTime: null, - - nodes: null, - - discretize: false, - numberOfValues: 256, -}; +function defaultValues(initialValues) { + return { + // Internal objects + buildTime: macro.obj({}), + nodes: [], + table: [], + + clamping: true, + colorSpace: ColorSpace.RGB, + hSVWrap: true, + scale: Scale.LINEAR, + + nanColor: [0.5, 0.0, 0.0, 1.0], + belowRangeColor: [0.0, 0.0, 0.0, 1.0], + aboveRangeColor: [1.0, 1.0, 1.0, 1.0], + useAboveRangeColor: false, + useBelowRangeColor: false, + + allowDuplicateScalars: false, + + tableSize: 0, + + discretize: false, + numberOfValues: 256, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkScalarsToColors.extend(publicAPI, model, initialValues); - // Internal objects initialization - model.table = []; - model.nodes = []; - - model.nanColor = [0.5, 0.0, 0.0, 1.0]; - model.belowRangeColor = [0.0, 0.0, 0.0, 1.0]; - model.aboveRangeColor = [1.0, 1.0, 1.0, 1.0]; - - model.buildTime = {}; - macro.obj(model.buildTime); + // setMappingRange requires previous value for model.mappingRange + model.mappingRange = initialValues.mappingRange; + delete initialValues.mappingRange; // Create get-only macros macro.get(publicAPI, model, ['buildTime', 'mappingRange']); From b70c1c967bf13e272547387df4fb6867ee60e8a1 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Mon, 13 Jun 2022 10:19:48 +0200 Subject: [PATCH 11/36] refactor(fielddata): improvement of getArrayWithIndexFix improvement of getArrayWithIndexFix --- .../DataModel/DataSetAttributes/FieldData.js | 6 ++---- .../Common/DataModel/DataSetAttributes/index.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index 6afdafc9e41..e83c1b904a1 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -59,15 +59,13 @@ function vtkFieldData(publicAPI, model) { ) : null; publicAPI.getArrayWithIndex = (arrayName) => - model.arrays - ? model.arrays.reduce( + (model.arrays || []).reduce( (a, b, i) => b.data && b.data.getName() === arrayName ? { array: b.data, index: i } : a, { array: null, index: -1 } - ) - : { array: null, index: -1 }; + ); publicAPI.getArrayByIndex = (idx) => idx >= 0 && idx < model.arrays.length ? model.arrays[idx].data : null; publicAPI.hasArray = (arrayName) => { diff --git a/Sources/Common/DataModel/DataSetAttributes/index.js b/Sources/Common/DataModel/DataSetAttributes/index.js index 933a1cedcf8..6c4fa4c4e8d 100644 --- a/Sources/Common/DataModel/DataSetAttributes/index.js +++ b/Sources/Common/DataModel/DataSetAttributes/index.js @@ -239,15 +239,15 @@ function vtkDataSetAttributes(publicAPI, model) { function defaultValues(initialValues) { return { - activeScalars: -1, - activeVectors: -1, - activeTensors: -1, - activeNormals: -1, - activeTCoords: -1, - activeGlobalIds: -1, - activePedigreeIds: -1, + activeScalars: -1, + activeVectors: -1, + activeTensors: -1, + activeNormals: -1, + activeTCoords: -1, + activeGlobalIds: -1, + activePedigreeIds: -1, ...initialValues, -}; + }; } // ---------------------------------------------------------------------------- From ea4736796496cc9d39b64601200852cdaf4687ca Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Mon, 13 Jun 2022 12:06:07 +0200 Subject: [PATCH 12/36] refactor(polydatamapper): put some values in default rather than set them in constructor put some values in default rather than set them in constructor --- .../DataModel/DataSetAttributes/FieldData.js | 10 ++-- Sources/Rendering/Core/RenderWindow/index.js | 3 + .../Rendering/OpenGL/PolyDataMapper/index.js | 55 +++++++++---------- .../OpenGL/PolyDataMapper2D/index.js | 26 ++++----- 4 files changed, 44 insertions(+), 50 deletions(-) diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index e83c1b904a1..997d2a43c59 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -60,11 +60,11 @@ function vtkFieldData(publicAPI, model) { : null; publicAPI.getArrayWithIndex = (arrayName) => (model.arrays || []).reduce( - (a, b, i) => - b.data && b.data.getName() === arrayName - ? { array: b.data, index: i } - : a, - { array: null, index: -1 } + (a, b, i) => + b.data && b.data.getName() === arrayName + ? { array: b.data, index: i } + : a, + { array: null, index: -1 } ); publicAPI.getArrayByIndex = (idx) => idx >= 0 && idx < model.arrays.length ? model.arrays[idx].data : null; diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index ab094976ae1..3dc5e4d3ccd 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -15,6 +15,9 @@ export function listViewAPIs() { return Object.keys(VIEW_CONSTRUCTORS); } +export function newAPISpecificView(name, initialValues = {}) { + return VIEW_CONSTRUCTORS[name] && VIEW_CONSTRUCTORS[name](initialValues); +} // ---------------------------------------------------------------------------- // Object factory diff --git a/Sources/Rendering/OpenGL/PolyDataMapper/index.js b/Sources/Rendering/OpenGL/PolyDataMapper/index.js index b6778b94378..b89743d94c4 100755 --- a/Sources/Rendering/OpenGL/PolyDataMapper/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper/index.js @@ -2012,27 +2012,39 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) { function defaultValues(initialValues) { return { - ambientColor: [], // used internally - diffuseColor: [], // used internally - specularColor: [], // used internally - lightColor: [], // used internally - lightHalfAngle: [], // used internally - lightDirection: [], // used internally + // Internal + tmpMat3: mat3.identity(new Float64Array(9)), + tmpMat4: mat4.identity(new Float64Array(16)), + + ambientColor: [], // used internally + diffuseColor: [], // used internally + specularColor: [], // used internally + lightColor: [], // used internally + lightHalfAngle: [], // used internally + lightDirection: [], // used internally VBOBuildTime: macro.obj({}, { mtime: 0 }), selectionStateChanged: macro.obj({}, { mtime: 0 }), context: null, VBOBuildString: null, - primitives: null, - primTypes: null, + primitives: Object.keys(primTypes).map((primType) => + vtkHelper.newInstance({ + primitiveType: primTypes[primType], + lastLightComplexity: 0, + lastLightCount: 0, + lastSelectionPass: false, + }) + ), + primTypes, shaderRebuildString: null, - lastHaveSeenDepthRequest: false, - haveSeenDepthRequest: false, - lastSelectionState: PassTypes.MIN_KNOWN_PASS - 1, - selectionWebGLIdsToVTKIds: null, - pointPicking: false, -}; + lastHaveSeenDepthRequest: false, + haveSeenDepthRequest: false, + lastSelectionState: PassTypes.MIN_KNOWN_PASS - 1, + selectionWebGLIdsToVTKIds: null, + pointPicking: false, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -2048,21 +2060,6 @@ export function extend(publicAPI, model, initialValues = {}) { initialValues ); - initialValues.primitives = []; - initialValues.primTypes = primTypes; - - initialValues.tmpMat3 = mat3.identity(new Float64Array(9)); - initialValues.tmpMat4 = mat4.identity(new Float64Array(16)); - - for (let i = primTypes.Start; i < primTypes.End; i++) { - initialValues.primitives[i] = vtkHelper.newInstance(); - initialValues.primitives[i].setPrimitiveType(i); - initialValues.primitives[i].set( - { lastLightComplexity: 0, lastLightCount: 0, lastSelectionPass: false }, - true - ); - } - // Build VTK API macro.setGet(publicAPI, model, ['context']); diff --git a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js index ffce329657d..337a54a16ca 100644 --- a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js @@ -30,10 +30,18 @@ const EndEvent = { type: 'EndEvent' }; function defaultValues(initialValues) { return { // Internal Objects + primitives: Object.keys(primTypes).map((primType) => + vtkHelper.newInstance({ + primitiveType: primTypes[primType], + lastLightComplexity: 0, + lastLightCount: 0, + lastSelectionPass: false, + }) + ), + primTypes, + tmpMat4: mat4.identity(new Float64Array(16)), VBOBuildTime: macro.obj({}, { mtime: 0 }), VBOBuildString: null, - primitives: null, - primTypes: null, context: null, shaderRebuildString: null, @@ -750,20 +758,6 @@ export function extend(publicAPI, model, initialValues = {}) { initialValues ); - initialValues.primitives = []; - initialValues.primTypes = primTypes; - - initialValues.tmpMat4 = mat4.identity(new Float64Array(16)); - - for (let i = primTypes.Start; i < primTypes.End; i++) { - initialValues.primitives[i] = vtkHelper.newInstance(); - initialValues.primitives[i].setPrimitiveType(i); - initialValues.primitives[i].set( - { lastLightComplexity: 0, lastLightCount: 0, lastSelectionPass: false }, - true - ); - } - // Build VTK API macro.setGet(publicAPI, model, ['context']); From 986dfc1fa479ec331ae726eedd74bf685449b24c Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 14 Jun 2022 14:04:10 +0200 Subject: [PATCH 13/36] fix(renderwindow): fix fix after refactoring --- Sources/Rendering/Core/RenderWindow/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index 3dc5e4d3ccd..f5072862711 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -15,8 +15,10 @@ export function listViewAPIs() { return Object.keys(VIEW_CONSTRUCTORS); } -export function newAPISpecificView(name, initialValues = {}) { - return VIEW_CONSTRUCTORS[name] && VIEW_CONSTRUCTORS[name](initialValues); +export function newAPISpecificView(name, initialValues = {}, toSet = true) { + return ( + VIEW_CONSTRUCTORS[name] && VIEW_CONSTRUCTORS[name](initialValues, toSet) + ); } // ---------------------------------------------------------------------------- @@ -173,7 +175,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderWindow'); +export const newInstance = macro.newInstance(extend, 'vtkRenderWindow', true); // ---------------------------------------------------------------------------- From 0672218ca2988c5ecaf17be1337d0d3b7b6a5331 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 14 Jun 2022 14:42:14 +0200 Subject: [PATCH 14/36] fix(abstractmapper): remove useless initialValues setting remove useless initialValues setting --- .../Rendering/Core/AbstractMapper/index.js | 4 ---- .../Rendering/Core/AbstractMapper3D/index.js | 21 +++++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Sources/Rendering/Core/AbstractMapper/index.js b/Sources/Rendering/Core/AbstractMapper/index.js index 13330adc0d9..73de89cd66a 100644 --- a/Sources/Rendering/Core/AbstractMapper/index.js +++ b/Sources/Rendering/Core/AbstractMapper/index.js @@ -107,10 +107,6 @@ export function extend(publicAPI, model, initialValues = {}) { macro.obj(publicAPI, model); macro.algo(publicAPI, model, 1, 0); - if (!initialValues.clippingPlanes) { - initialValues.clippingPlanes = []; - } - vtkAbstractMapper(publicAPI, model); } diff --git a/Sources/Rendering/Core/AbstractMapper3D/index.js b/Sources/Rendering/Core/AbstractMapper3D/index.js index 7f0f71b99cd..10f1654547f 100644 --- a/Sources/Rendering/Core/AbstractMapper3D/index.js +++ b/Sources/Rendering/Core/AbstractMapper3D/index.js @@ -39,24 +39,23 @@ function vtkAbstractMapper3D(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - bounds: [1, -1, 1, -1, 1, -1], - center: [0, 0, 0], -}; +function defaultValues(initialValues) { + return { + bounds: [1, -1, 1, -1, 1, -1], + center: [0, 0, 0], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkAbstractMapper.extend(publicAPI, model, initialValues); - if (!model.bounds) { - vtkMath.uninitializeBounds(model.bounds); - } - - if (!model.center) { - model.center = [0.0, 0.0, 0.0]; + if (!initialValues.bounds) { + vtkMath.uninitializeBounds(initialValues.bounds); } vtkAbstractMapper3D(publicAPI, model); From 62ca1dd619118649f53ae43bc51679ef14da0a6f Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 14 Jun 2022 14:52:54 +0200 Subject: [PATCH 15/36] refactor(filtersources): refactor constructors to call setters call setters when creating the object --- .../Filters/Sources/Arrow2DSource/index.js | 2 +- Sources/Filters/Sources/ArrowSource/index.js | 25 ++++++---- Sources/Filters/Sources/CircleSource/index.js | 2 +- .../Sources/ConcentricCylinderSource/index.js | 32 ++++++------ Sources/Filters/Sources/ConeSource/index.js | 23 +++++---- Sources/Filters/Sources/Cursor3D/index.js | 44 +++++++++------- .../Filters/Sources/CylinderSource/index.js | 25 ++++++---- .../Filters/Sources/ImageGridSource/index.js | 25 ++++++---- Sources/Filters/Sources/LineSource/index.js | 17 ++++--- Sources/Filters/Sources/PlaneSource/index.js | 50 +++++++++++++------ 10 files changed, 144 insertions(+), 101 deletions(-) diff --git a/Sources/Filters/Sources/Arrow2DSource/index.js b/Sources/Filters/Sources/Arrow2DSource/index.js index 4dc02785e17..364cc854d41 100644 --- a/Sources/Filters/Sources/Arrow2DSource/index.js +++ b/Sources/Filters/Sources/Arrow2DSource/index.js @@ -197,7 +197,7 @@ function defaultValues(initialValues) { // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, defaultValues(initialValues)); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/ArrowSource/index.js b/Sources/Filters/Sources/ArrowSource/index.js index 947c745dc56..760404ea8d1 100644 --- a/Sources/Filters/Sources/ArrowSource/index.js +++ b/Sources/Filters/Sources/ArrowSource/index.js @@ -90,21 +90,24 @@ function vtkArrowSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - tipResolution: 6, - tipRadius: 0.1, - tipLength: 0.35, - shaftResolution: 6, - shaftRadius: 0.03, - invert: false, - direction: [1.0, 0.0, 0.0], - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + tipResolution: 6, + tipRadius: 0.1, + tipLength: 0.35, + shaftResolution: 6, + shaftRadius: 0.03, + invert: false, + direction: [1.0, 0.0, 0.0], + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/CircleSource/index.js b/Sources/Filters/Sources/CircleSource/index.js index a42a33f25c9..0c51b851199 100644 --- a/Sources/Filters/Sources/CircleSource/index.js +++ b/Sources/Filters/Sources/CircleSource/index.js @@ -84,7 +84,7 @@ function defaultValues(initialValues) { // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, defaultValues(initialValues)); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/ConcentricCylinderSource/index.js b/Sources/Filters/Sources/ConcentricCylinderSource/index.js index 153266e3c8a..3b6aaff4986 100644 --- a/Sources/Filters/Sources/ConcentricCylinderSource/index.js +++ b/Sources/Filters/Sources/ConcentricCylinderSource/index.js @@ -36,6 +36,7 @@ function vtkConcentricCylinderSource(publicAPI, model) { publicAPI.getNumberOfRadius = () => model.radius.length; publicAPI.getRadius = (index = 0) => model.radius[index]; publicAPI.setRadius = (index, radius) => { + if (!model.radius) model.radius = []; model.radius[index] = radius; publicAPI.modified(); }; @@ -403,24 +404,27 @@ function vtkConcentricCylinderSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - height: 1.0, - radius: [0.5], - cellFields: [1], - resolution: 6, - startTheta: 0.0, - endTheta: 360.0, - center: [0, 0, 0], - direction: [0.0, 0.0, 1.0], - skipInnerFaces: true, - mask: null, // If present, array to know if a layer should be skipped(=true) - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + height: 1.0, + radius: [0.5], + cellFields: [1], + resolution: 6, + startTheta: 0.0, + endTheta: 360.0, + center: [0, 0, 0], + direction: [0.0, 0.0, 1.0], + skipInnerFaces: true, + mask: null, // If present, array to know if a layer should be skipped(=true) + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/ConeSource/index.js b/Sources/Filters/Sources/ConeSource/index.js index c912b73c060..bdc28f8605f 100644 --- a/Sources/Filters/Sources/ConeSource/index.js +++ b/Sources/Filters/Sources/ConeSource/index.js @@ -84,20 +84,23 @@ function vtkConeSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - height: 1.0, - radius: 0.5, - resolution: 6, - center: [0, 0, 0], - direction: [1.0, 0.0, 0.0], - capping: true, - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + height: 1.0, + radius: 0.5, + resolution: 6, + center: [0, 0, 0], + direction: [1.0, 0.0, 0.0], + capping: true, + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/Cursor3D/index.js b/Sources/Filters/Sources/Cursor3D/index.js index aefd608fb5d..a5472aa01c4 100644 --- a/Sources/Filters/Sources/Cursor3D/index.js +++ b/Sources/Filters/Sources/Cursor3D/index.js @@ -2,6 +2,27 @@ import macro from 'vtk.js/Sources/macros'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray'; import vtkPoints from 'vtk.js/Sources/Common/Core/Points'; + +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + focus: null, + modelBounds: [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0], + focalPoint: [0.0, 0.0, 0.0], + outline: true, + axes: true, + xShadows: true, + yShadows: true, + zShadows: true, + wrap: false, + translationMode: false, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- // vtkCursor3D methods // ---------------------------------------------------------------------------- @@ -15,6 +36,7 @@ function vtkCursor3D(publicAPI, model) { return; } if ( + model.modelBounds && model.modelBounds[0] === bounds[0] && model.modelBounds[1] === bounds[1] && model.modelBounds[2] === bounds[2] && @@ -41,6 +63,7 @@ function vtkCursor3D(publicAPI, model) { if (!Array.isArray(points) || points.length < 3) { return; } + if (!model.focalPoint) model.focalPoint = defaultValues().focalPoint; if ( points[0] === model.focalPoint[0] && points[1] === model.focalPoint[1] && @@ -388,27 +411,10 @@ function vtkCursor3D(publicAPI, model) { }; } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -const DEFAULT_VALUES = { - focus: null, - modelBounds: [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0], - focalPoint: [0.0, 0.0, 0.0], - outline: true, - axes: true, - xShadows: true, - yShadows: true, - zShadows: true, - wrap: false, - translationMode: false, -}; - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API // Cursor3D @@ -429,7 +435,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCursor3D'); +export const newInstance = macro.newInstance(extend, 'vtkCursor3D', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/CylinderSource/index.js b/Sources/Filters/Sources/CylinderSource/index.js index 6139d13f6a5..9abb1c4766a 100644 --- a/Sources/Filters/Sources/CylinderSource/index.js +++ b/Sources/Filters/Sources/CylinderSource/index.js @@ -178,21 +178,24 @@ function vtkCylinderSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - height: 1.0, - initAngle: 0, - radius: 1.0, - resolution: 6, - center: [0, 0, 0], - direction: [0.0, 1.0, 0.0], - capping: true, - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + height: 1.0, + initAngle: 0, + radius: 1.0, + resolution: 6, + center: [0, 0, 0], + direction: [0.0, 1.0, 0.0], + capping: true, + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/ImageGridSource/index.js b/Sources/Filters/Sources/ImageGridSource/index.js index 27c9e3e785c..ba598cd2b56 100644 --- a/Sources/Filters/Sources/ImageGridSource/index.js +++ b/Sources/Filters/Sources/ImageGridSource/index.js @@ -96,21 +96,24 @@ function vtkImageGridSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - lineValue: 0, - fillValue: 255, - gridSpacing: [10, 10, 0], - gridOrigin: [0, 0, 0], - dataSpacing: [1.0, 1.0, 1.0], - dataOrigin: [0.0, 0.0, 0.0], - dataExtent: [0, 255, 0, 255, 0, 0], - dataDirection: [1, 0, 0, 0, 1, 0, 0, 0, 1], -}; +function defaultValues(initialValues) { + return { + lineValue: 0, + fillValue: 255, + gridSpacing: [10, 10, 0], + gridOrigin: [0, 0, 0], + dataSpacing: [1.0, 1.0, 1.0], + dataOrigin: [0.0, 0.0, 0.0], + dataExtent: [0, 255, 0, 255, 0, 0], + dataDirection: [1, 0, 0, 0, 1, 0, 0, 0, 1], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/LineSource/index.js b/Sources/Filters/Sources/LineSource/index.js index 614e0def70b..c9204b25c67 100644 --- a/Sources/Filters/Sources/LineSource/index.js +++ b/Sources/Filters/Sources/LineSource/index.js @@ -72,17 +72,20 @@ function vtkLineSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - resolution: 10, - point1: [-1, 0, 0], - point2: [1, 0, 0], - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + resolution: 10, + point1: [-1, 0, 0], + point2: [1, 0, 0], + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); diff --git a/Sources/Filters/Sources/PlaneSource/index.js b/Sources/Filters/Sources/PlaneSource/index.js index 45bf7efc4f5..0555c099fe7 100644 --- a/Sources/Filters/Sources/PlaneSource/index.js +++ b/Sources/Filters/Sources/PlaneSource/index.js @@ -122,7 +122,13 @@ function vtkPlaneSource(publicAPI, model) { n = [normal[0], normal[1], normal[2]]; } - if (vtkMath.normalize(n) !== 0) { + const normN = vtkMath.normalize(n); + // If we are at instanciation time + if (model.normal === undefined) { + model.normal = n; + } + + if (normN !== 0) { const dp = vtkMath.dot(model.normal, n); let theta = 0; @@ -180,6 +186,11 @@ function vtkPlaneSource(publicAPI, model) { c = [center[0], center[1], center[2]]; } + // If we are at instanciation time + if (model.center === undefined) { + model.center = c; + } + if (!vec3.exactEquals(c, model.center)) { const v1 = []; vtkMath.subtract(model.point1, model.origin, v1); @@ -206,6 +217,9 @@ function vtkPlaneSource(publicAPI, model) { point1 = [point[0], point[1], point[2]]; } + // If we are at instanciation time + if (model.point1 === undefined) model.point1 = point1; + if (!vec3.exactEquals(point1, model.point1)) { const v1 = []; const v2 = []; @@ -229,6 +243,9 @@ function vtkPlaneSource(publicAPI, model) { point2 = [point[0], point[1], point[2]]; } + // If we are at instanciation time + if (model.point2 === undefined) model.point2 = point2; + if (!vec3.exactEquals(point2, model.point2)) { const v1 = []; const v2 = []; @@ -260,22 +277,26 @@ function vtkPlaneSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - xResolution: 10, - yResolution: 10, - origin: [0, 0, 0], - point1: [1, 0, 0], - point2: [0, 1, 0], - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + // Internal + normal: [0, 0, 1], + center: [0, 0, 0], + + xResolution: 10, + yResolution: 10, + origin: [0, 0, 0], + point1: [1, 0, 0], + point2: [0, 1, 0], + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - - model.normal = [0, 0, 1]; - model.center = [0, 0, 0]; + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -285,9 +306,6 @@ export function extend(publicAPI, model, initialValues = {}) { macro.algo(publicAPI, model, 0, 1); vtkPlaneSource(publicAPI, model); - - publicAPI.setPoint1(model.point1); - publicAPI.setPoint2(model.point2); } // ---------------------------------------------------------------------------- From 763e1cf5ca0895b779c5c6dd860d844dc6988e54 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 14 Jun 2022 15:48:28 +0200 Subject: [PATCH 16/36] fix(renderwindow): fix after refactor fix after refactor (remove tmp true in newinstance) --- Sources/Rendering/Core/RenderWindow/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index f5072862711..cf259eea652 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -175,7 +175,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderWindow', true); +export const newInstance = macro.newInstance(extend, 'vtkRenderWindow'); // ---------------------------------------------------------------------------- From d607ff717f45f9e6b009a5339c2e0403e94a4def Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Tue, 14 Jun 2022 16:26:14 +0200 Subject: [PATCH 17/36] refactor(tmp): temporary to only call setters for modified files Temporary to only call setters for modified files --- Sources/Common/Core/CellArray/index.js | 2 +- Sources/Common/Core/DataArray/index.js | 2 +- .../Common/Core/DataArray/test/testDataArray.js | 17 ++++++++++++++++- Sources/Common/Core/LookupTable/index.js | 2 +- Sources/Common/Core/Points/index.js | 2 +- Sources/Common/Core/ScalarsToColors/index.js | 6 +++++- .../DataModel/DataSetAttributes/FieldData.js | 2 +- .../Common/DataModel/DataSetAttributes/index.js | 6 +++++- Sources/Common/DataModel/SelectionNode/index.js | 2 +- Sources/Filters/Sources/Arrow2DSource/index.js | 2 +- Sources/Filters/Sources/ArrowSource/index.js | 2 +- Sources/Filters/Sources/CircleSource/index.js | 2 +- .../Sources/ConcentricCylinderSource/index.js | 3 ++- Sources/Filters/Sources/ConeSource/index.js | 2 +- Sources/Filters/Sources/CubeSource/index.js | 2 +- Sources/Filters/Sources/CylinderSource/index.js | 2 +- .../Filters/Sources/ImageGridSource/index.js | 6 +++++- Sources/Filters/Sources/LineSource/index.js | 2 +- Sources/Filters/Sources/PlaneSource/index.js | 2 +- Sources/Filters/Sources/SphereSource/index.js | 2 +- Sources/Rendering/Core/Actor/index.js | 2 +- Sources/Rendering/Core/Actor2D/index.js | 2 +- .../Rendering/Core/Actor2D/test/testActor2D.js | 2 +- Sources/Rendering/Core/Camera/index.js | 2 +- .../Core/ColorTransferFunction/index.js | 3 ++- Sources/Rendering/Core/Coordinate/index.js | 2 +- .../Rendering/Core/HardwareSelector/index.js | 6 +++++- Sources/Rendering/Core/Light/index.js | 2 +- Sources/Rendering/Core/Mapper/index.js | 2 +- Sources/Rendering/Core/Mapper2D/index.js | 2 +- Sources/Rendering/Core/Prop/index.js | 2 +- Sources/Rendering/Core/Prop3D/index.js | 2 +- Sources/Rendering/Core/Property/index.js | 2 +- Sources/Rendering/Core/Property2D/index.js | 2 +- Sources/Rendering/Core/RenderWindow/index.js | 2 +- Sources/Rendering/Core/Renderer/index.js | 2 +- Sources/Rendering/Core/Viewport/index.js | 2 +- .../Misc/FullScreenRenderWindow/index.js | 2 +- Sources/Rendering/OpenGL/Actor/index.js | 2 +- Sources/Rendering/OpenGL/Actor2D/index.js | 2 +- Sources/Rendering/OpenGL/Camera/index.js | 2 +- .../Rendering/OpenGL/HardwareSelector/index.js | 3 ++- .../Rendering/OpenGL/PolyDataMapper/index.js | 6 +++++- .../Rendering/OpenGL/PolyDataMapper2D/index.js | 3 ++- Sources/Rendering/OpenGL/RenderWindow/index.js | 6 +++++- Sources/Rendering/OpenGL/Renderer/index.js | 2 +- Sources/Rendering/OpenGL/Shader/index.js | 2 +- Sources/Rendering/OpenGL/ShaderCache/index.js | 2 +- Sources/Rendering/OpenGL/ShaderProgram/index.js | 2 +- .../Rendering/OpenGL/ViewNodeFactory/index.js | 3 ++- .../Rendering/SceneGraph/RenderPass/index.js | 2 +- .../SceneGraph/RenderWindowViewNode/index.js | 6 +++++- Sources/Rendering/SceneGraph/ViewNode/index.js | 2 +- .../SceneGraph/ViewNodeFactory/index.js | 6 +++++- Sources/Rendering/WebGPU/Actor/index.js | 2 +- Sources/Rendering/WebGPU/Camera/index.js | 2 +- .../WebGPU/HardwareSelectionPass/index.js | 3 ++- .../Rendering/WebGPU/HardwareSelector/index.js | 3 ++- Sources/Rendering/WebGPU/RenderWindow/index.js | 6 +++++- Sources/Rendering/WebGPU/Renderer/index.js | 2 +- Sources/Rendering/WebGPU/ShaderCache/index.js | 6 +++++- .../Rendering/WebGPU/ViewNodeFactory/index.js | 3 ++- Sources/macros.js | 6 +++--- Sources/vtk.js | 2 +- 64 files changed, 129 insertions(+), 66 deletions(-) diff --git a/Sources/Common/Core/CellArray/index.js b/Sources/Common/Core/CellArray/index.js index 706bf8859fd..4c593074bc4 100644 --- a/Sources/Common/Core/CellArray/index.js +++ b/Sources/Common/Core/CellArray/index.js @@ -108,7 +108,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCellArray'); +export const newInstance = macro.newInstance(extend, 'vtkCellArray', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/DataArray/index.js b/Sources/Common/Core/DataArray/index.js index 231096edc51..c4e73db146a 100644 --- a/Sources/Common/Core/DataArray/index.js +++ b/Sources/Common/Core/DataArray/index.js @@ -380,7 +380,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkDataArray'); +export const newInstance = macro.newInstance(extend, 'vtkDataArray', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/DataArray/test/testDataArray.js b/Sources/Common/Core/DataArray/test/testDataArray.js index fe5aee86270..ec6eff47961 100644 --- a/Sources/Common/Core/DataArray/test/testDataArray.js +++ b/Sources/Common/Core/DataArray/test/testDataArray.js @@ -49,7 +49,7 @@ test('Test vtkDataArray instance', (t) => { values: null, }, getDataArrayProperties(dataArray0), - 'initialValues.data = null' + 'initialValues.values = null' ); const dataArray1 = vtkDataArray.newInstance({ size: 256 }); @@ -141,6 +141,21 @@ test('Test vtkDataArray instance', (t) => { 'Give numberOfComponents!=1 with empty array' ); + const dataArray7 = vtkDataArray.newInstance({ + size: 3, + numberOfComponents: 3, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 3, + values: macro.newTypedArray(DefaultDataType, 3), + }, + getDataArrayProperties(dataArray7), + 'Give only size to create instance' + ); + t.end(); }); diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index f59828b8da5..0d9a11e2b06 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -391,7 +391,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkLookupTable'); +export const newInstance = macro.newInstance(extend, 'vtkLookupTable', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/Points/index.js b/Sources/Common/Core/Points/index.js index b3e4665e2b6..c3f8108464c 100644 --- a/Sources/Common/Core/Points/index.js +++ b/Sources/Common/Core/Points/index.js @@ -103,7 +103,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkPoints'); +export const newInstance = macro.newInstance(extend, 'vtkPoints', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/ScalarsToColors/index.js b/Sources/Common/Core/ScalarsToColors/index.js index 8a20aac7955..9f519d6f90c 100644 --- a/Sources/Common/Core/ScalarsToColors/index.js +++ b/Sources/Common/Core/ScalarsToColors/index.js @@ -562,7 +562,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkScalarsToColors'); +export const newInstance = macro.newInstance( + extend, + 'vtkScalarsToColors', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index 997d2a43c59..4671c3b6231 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -209,7 +209,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkFieldData'); +export const newInstance = macro.newInstance(extend, 'vtkFieldData', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/DataModel/DataSetAttributes/index.js b/Sources/Common/DataModel/DataSetAttributes/index.js index 6c4fa4c4e8d..41a19c878f1 100644 --- a/Sources/Common/DataModel/DataSetAttributes/index.js +++ b/Sources/Common/DataModel/DataSetAttributes/index.js @@ -277,7 +277,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkDataSetAttributes'); +export const newInstance = macro.newInstance( + extend, + 'vtkDataSetAttributes', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/DataModel/SelectionNode/index.js b/Sources/Common/DataModel/SelectionNode/index.js index d8e2fa964b2..99273d62d28 100644 --- a/Sources/Common/DataModel/SelectionNode/index.js +++ b/Sources/Common/DataModel/SelectionNode/index.js @@ -46,7 +46,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkSelectionNode'); +export const newInstance = macro.newInstance(extend, 'vtkSelectionNode', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/Arrow2DSource/index.js b/Sources/Filters/Sources/Arrow2DSource/index.js index 364cc854d41..7fc5879eb89 100644 --- a/Sources/Filters/Sources/Arrow2DSource/index.js +++ b/Sources/Filters/Sources/Arrow2DSource/index.js @@ -209,7 +209,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkArrow2DSource'); +export const newInstance = macro.newInstance(extend, 'vtkArrow2DSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/ArrowSource/index.js b/Sources/Filters/Sources/ArrowSource/index.js index 760404ea8d1..0ae22bd90c2 100644 --- a/Sources/Filters/Sources/ArrowSource/index.js +++ b/Sources/Filters/Sources/ArrowSource/index.js @@ -126,7 +126,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkArrowSource'); +export const newInstance = macro.newInstance(extend, 'vtkArrowSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/CircleSource/index.js b/Sources/Filters/Sources/CircleSource/index.js index 0c51b851199..55a85f2bbb7 100644 --- a/Sources/Filters/Sources/CircleSource/index.js +++ b/Sources/Filters/Sources/CircleSource/index.js @@ -96,7 +96,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCircleSource'); +export const newInstance = macro.newInstance(extend, 'vtkCircleSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/ConcentricCylinderSource/index.js b/Sources/Filters/Sources/ConcentricCylinderSource/index.js index 3b6aaff4986..c69584ccc86 100644 --- a/Sources/Filters/Sources/ConcentricCylinderSource/index.js +++ b/Sources/Filters/Sources/ConcentricCylinderSource/index.js @@ -445,7 +445,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkConcentricCylinderSource' + 'vtkConcentricCylinderSource', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/ConeSource/index.js b/Sources/Filters/Sources/ConeSource/index.js index bdc28f8605f..9cd626093a5 100644 --- a/Sources/Filters/Sources/ConeSource/index.js +++ b/Sources/Filters/Sources/ConeSource/index.js @@ -112,7 +112,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkConeSource'); +export const newInstance = macro.newInstance(extend, 'vtkConeSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/CubeSource/index.js b/Sources/Filters/Sources/CubeSource/index.js index 40db9915653..2dd03b1018b 100644 --- a/Sources/Filters/Sources/CubeSource/index.js +++ b/Sources/Filters/Sources/CubeSource/index.js @@ -301,7 +301,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCubeSource'); +export const newInstance = macro.newInstance(extend, 'vtkCubeSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/CylinderSource/index.js b/Sources/Filters/Sources/CylinderSource/index.js index 9abb1c4766a..14653e0177f 100644 --- a/Sources/Filters/Sources/CylinderSource/index.js +++ b/Sources/Filters/Sources/CylinderSource/index.js @@ -214,7 +214,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCylinderSource'); +export const newInstance = macro.newInstance(extend, 'vtkCylinderSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/ImageGridSource/index.js b/Sources/Filters/Sources/ImageGridSource/index.js index ba598cd2b56..2a2da2574c4 100644 --- a/Sources/Filters/Sources/ImageGridSource/index.js +++ b/Sources/Filters/Sources/ImageGridSource/index.js @@ -137,7 +137,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkImageGridSource'); +export const newInstance = macro.newInstance( + extend, + 'vtkImageGridSource', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/LineSource/index.js b/Sources/Filters/Sources/LineSource/index.js index c9204b25c67..fa53084c76e 100644 --- a/Sources/Filters/Sources/LineSource/index.js +++ b/Sources/Filters/Sources/LineSource/index.js @@ -97,7 +97,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkLineSource'); +export const newInstance = macro.newInstance(extend, 'vtkLineSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/PlaneSource/index.js b/Sources/Filters/Sources/PlaneSource/index.js index 0555c099fe7..fe5917bdd8c 100644 --- a/Sources/Filters/Sources/PlaneSource/index.js +++ b/Sources/Filters/Sources/PlaneSource/index.js @@ -310,7 +310,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkPlaneSource'); +export const newInstance = macro.newInstance(extend, 'vtkPlaneSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/SphereSource/index.js b/Sources/Filters/Sources/SphereSource/index.js index 264daa3819c..08559427b61 100644 --- a/Sources/Filters/Sources/SphereSource/index.js +++ b/Sources/Filters/Sources/SphereSource/index.js @@ -241,7 +241,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkSphereSource'); +export const newInstance = macro.newInstance(extend, 'vtkSphereSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Actor/index.js b/Sources/Rendering/Core/Actor/index.js index 3be372fe188..1f5e1f4f49a 100644 --- a/Sources/Rendering/Core/Actor/index.js +++ b/Sources/Rendering/Core/Actor/index.js @@ -211,7 +211,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkActor'); +export const newInstance = macro.newInstance(extend, 'vtkActor', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Actor2D/index.js b/Sources/Rendering/Core/Actor2D/index.js index 7a143090488..19436acd25b 100644 --- a/Sources/Rendering/Core/Actor2D/index.js +++ b/Sources/Rendering/Core/Actor2D/index.js @@ -173,7 +173,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkActor2D'); +export const newInstance = macro.newInstance(extend, 'vtkActor2D', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Actor2D/test/testActor2D.js b/Sources/Rendering/Core/Actor2D/test/testActor2D.js index 2c0dbe27da5..a6fff819048 100644 --- a/Sources/Rendering/Core/Actor2D/test/testActor2D.js +++ b/Sources/Rendering/Core/Actor2D/test/testActor2D.js @@ -16,7 +16,7 @@ import { Representation } from 'vtk.js/Sources/Rendering/Core/Property/Constants import baseline from './testActor2D.png'; -test('Test Actor2D', (t) => { +test.only('Test Actor2D', (t) => { const gc = testUtils.createGarbageCollector(t); t.ok('rendering', 'vtkActor2D'); diff --git a/Sources/Rendering/Core/Camera/index.js b/Sources/Rendering/Core/Camera/index.js index 751832f24e7..a6f5720b4c7 100644 --- a/Sources/Rendering/Core/Camera/index.js +++ b/Sources/Rendering/Core/Camera/index.js @@ -815,7 +815,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCamera'); +export const newInstance = macro.newInstance(extend, 'vtkCamera', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/ColorTransferFunction/index.js b/Sources/Rendering/Core/ColorTransferFunction/index.js index 97f893a2507..f3a1146c5fc 100644 --- a/Sources/Rendering/Core/ColorTransferFunction/index.js +++ b/Sources/Rendering/Core/ColorTransferFunction/index.js @@ -1273,7 +1273,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkColorTransferFunction' + 'vtkColorTransferFunction', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Coordinate/index.js b/Sources/Rendering/Core/Coordinate/index.js index a544bf95a48..28363a2d69b 100644 --- a/Sources/Rendering/Core/Coordinate/index.js +++ b/Sources/Rendering/Core/Coordinate/index.js @@ -622,7 +622,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCoordinate'); +export const newInstance = macro.newInstance(extend, 'vtkCoordinate', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/HardwareSelector/index.js b/Sources/Rendering/Core/HardwareSelector/index.js index ea9830d2960..db7b404a9d5 100644 --- a/Sources/Rendering/Core/HardwareSelector/index.js +++ b/Sources/Rendering/Core/HardwareSelector/index.js @@ -59,7 +59,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkHardwareSelector'); +export const newInstance = macro.newInstance( + extend, + 'vtkHardwareSelector', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Light/index.js b/Sources/Rendering/Core/Light/index.js index 07f22bdf059..dd1a300fe6c 100644 --- a/Sources/Rendering/Core/Light/index.js +++ b/Sources/Rendering/Core/Light/index.js @@ -139,7 +139,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkLight'); +export const newInstance = macro.newInstance(extend, 'vtkLight', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Mapper/index.js b/Sources/Rendering/Core/Mapper/index.js index 695e9d7bcdc..284b6f44f22 100644 --- a/Sources/Rendering/Core/Mapper/index.js +++ b/Sources/Rendering/Core/Mapper/index.js @@ -651,7 +651,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkMapper'); +export const newInstance = macro.newInstance(extend, 'vtkMapper', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Mapper2D/index.js b/Sources/Rendering/Core/Mapper2D/index.js index f34bd941c18..6c0a61a5356 100644 --- a/Sources/Rendering/Core/Mapper2D/index.js +++ b/Sources/Rendering/Core/Mapper2D/index.js @@ -206,7 +206,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkMapper2D'); +export const newInstance = macro.newInstance(extend, 'vtkMapper2D', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Prop/index.js b/Sources/Rendering/Core/Prop/index.js index 93e1ee55acf..aad813b96f5 100644 --- a/Sources/Rendering/Core/Prop/index.js +++ b/Sources/Rendering/Core/Prop/index.js @@ -135,7 +135,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkProp'); +export const newInstance = macro.newInstance(extend, 'vtkProp', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index b17ac42bb5b..9454207da06 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -212,7 +212,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkProp3D'); +export const newInstance = macro.newInstance(extend, 'vtkProp3D', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Property/index.js b/Sources/Rendering/Core/Property/index.js index c3c9f7708c3..3dfb4fdf6a6 100644 --- a/Sources/Rendering/Core/Property/index.js +++ b/Sources/Rendering/Core/Property/index.js @@ -154,7 +154,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkProperty'); +export const newInstance = macro.newInstance(extend, 'vtkProperty', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Property2D/index.js b/Sources/Rendering/Core/Property2D/index.js index 2d7b04b09c9..c3dcbda81c9 100644 --- a/Sources/Rendering/Core/Property2D/index.js +++ b/Sources/Rendering/Core/Property2D/index.js @@ -65,7 +65,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkProperty2D'); +export const newInstance = macro.newInstance(extend, 'vtkProperty2D', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index cf259eea652..f5072862711 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -175,7 +175,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderWindow'); +export const newInstance = macro.newInstance(extend, 'vtkRenderWindow', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Renderer/index.js b/Sources/Rendering/Core/Renderer/index.js index 08d63b9b88d..1bb1ba08eda 100644 --- a/Sources/Rendering/Core/Renderer/index.js +++ b/Sources/Rendering/Core/Renderer/index.js @@ -681,7 +681,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderer'); +export const newInstance = macro.newInstance(extend, 'vtkRenderer', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Viewport/index.js b/Sources/Rendering/Core/Viewport/index.js index 9c32fd8ef4a..253e5554979 100644 --- a/Sources/Rendering/Core/Viewport/index.js +++ b/Sources/Rendering/Core/Viewport/index.js @@ -171,7 +171,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkViewport'); +export const newInstance = macro.newInstance(extend, 'vtkViewport', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Misc/FullScreenRenderWindow/index.js b/Sources/Rendering/Misc/FullScreenRenderWindow/index.js index a16affd059f..565b8de3aa9 100644 --- a/Sources/Rendering/Misc/FullScreenRenderWindow/index.js +++ b/Sources/Rendering/Misc/FullScreenRenderWindow/index.js @@ -220,7 +220,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/Actor/index.js b/Sources/Rendering/OpenGL/Actor/index.js index 874830eaee3..05cfe25ff76 100644 --- a/Sources/Rendering/OpenGL/Actor/index.js +++ b/Sources/Rendering/OpenGL/Actor/index.js @@ -219,7 +219,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/Actor2D/index.js b/Sources/Rendering/OpenGL/Actor2D/index.js index 613d1ab4dbe..78a81955dff 100644 --- a/Sources/Rendering/OpenGL/Actor2D/index.js +++ b/Sources/Rendering/OpenGL/Actor2D/index.js @@ -194,7 +194,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/Camera/index.js b/Sources/Rendering/OpenGL/Camera/index.js index e372fd38b3b..48c81b81068 100644 --- a/Sources/Rendering/OpenGL/Camera/index.js +++ b/Sources/Rendering/OpenGL/Camera/index.js @@ -121,7 +121,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/HardwareSelector/index.js b/Sources/Rendering/OpenGL/HardwareSelector/index.js index a2dbac1ecd4..5397657cff6 100644 --- a/Sources/Rendering/OpenGL/HardwareSelector/index.js +++ b/Sources/Rendering/OpenGL/HardwareSelector/index.js @@ -948,7 +948,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkOpenGLHardwareSelector' + 'vtkOpenGLHardwareSelector', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/PolyDataMapper/index.js b/Sources/Rendering/OpenGL/PolyDataMapper/index.js index b89743d94c4..137ae2fbbc8 100755 --- a/Sources/Rendering/OpenGL/PolyDataMapper/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper/index.js @@ -2069,7 +2069,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLPolyDataMapper'); +export const newInstance = macro.newInstance( + extend, + 'vtkOpenGLPolyDataMapper', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js index 337a54a16ca..fda5a4eb8e5 100644 --- a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js @@ -769,7 +769,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkOpenGLPolyDataMapper2D' + 'vtkOpenGLPolyDataMapper2D', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/RenderWindow/index.js b/Sources/Rendering/OpenGL/RenderWindow/index.js index 00d88127fb2..fa7ea95fe57 100644 --- a/Sources/Rendering/OpenGL/RenderWindow/index.js +++ b/Sources/Rendering/OpenGL/RenderWindow/index.js @@ -1326,7 +1326,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLRenderWindow'); +export const newInstance = macro.newInstance( + extend, + 'vtkOpenGLRenderWindow', + true +); // ---------------------------------------------------------------------------- // Register API specific RenderWindow implementation diff --git a/Sources/Rendering/OpenGL/Renderer/index.js b/Sources/Rendering/OpenGL/Renderer/index.js index cea59058cc5..b771e309676 100644 --- a/Sources/Rendering/OpenGL/Renderer/index.js +++ b/Sources/Rendering/OpenGL/Renderer/index.js @@ -217,7 +217,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLRenderer'); +export const newInstance = macro.newInstance(extend, 'vtkOpenGLRenderer', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/Shader/index.js b/Sources/Rendering/OpenGL/Shader/index.js index f767ba237d0..f517b1e9ec6 100644 --- a/Sources/Rendering/OpenGL/Shader/index.js +++ b/Sources/Rendering/OpenGL/Shader/index.js @@ -109,7 +109,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkShader'); +export const newInstance = macro.newInstance(extend, 'vtkShader', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ShaderCache/index.js b/Sources/Rendering/OpenGL/ShaderCache/index.js index 87fb326f4f9..9f6720959dc 100644 --- a/Sources/Rendering/OpenGL/ShaderCache/index.js +++ b/Sources/Rendering/OpenGL/ShaderCache/index.js @@ -262,7 +262,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkShaderCache'); +export const newInstance = macro.newInstance(extend, 'vtkShaderCache', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ShaderProgram/index.js b/Sources/Rendering/OpenGL/ShaderProgram/index.js index 4a871126c54..fdd1bff2888 100644 --- a/Sources/Rendering/OpenGL/ShaderProgram/index.js +++ b/Sources/Rendering/OpenGL/ShaderProgram/index.js @@ -602,7 +602,7 @@ function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -const newInstance = macro.newInstance(extend, 'vtkShaderProgram'); +const newInstance = macro.newInstance(extend, 'vtkShaderProgram', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js index 941bc32488b..ccdf5c46394 100644 --- a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js +++ b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js @@ -43,7 +43,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkOpenGLViewNodeFactory' + 'vtkOpenGLViewNodeFactory', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/SceneGraph/RenderPass/index.js b/Sources/Rendering/SceneGraph/RenderPass/index.js index 0b2888ebbdc..303e8f3bb75 100644 --- a/Sources/Rendering/SceneGraph/RenderPass/index.js +++ b/Sources/Rendering/SceneGraph/RenderPass/index.js @@ -83,7 +83,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderPass'); +export const newInstance = macro.newInstance(extend, 'vtkRenderPass', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index d1853f8845a..b3d5c45a2ea 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -178,7 +178,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRenderWindowViewNode'); +export const newInstance = macro.newInstance( + extend, + 'vtkRenderWindowViewNode', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/SceneGraph/ViewNode/index.js b/Sources/Rendering/SceneGraph/ViewNode/index.js index 2688501beda..68e094daf3b 100644 --- a/Sources/Rendering/SceneGraph/ViewNode/index.js +++ b/Sources/Rendering/SceneGraph/ViewNode/index.js @@ -222,7 +222,7 @@ function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -const newInstance = macro.newInstance(extend, 'vtkViewNode'); +const newInstance = macro.newInstance(extend, 'vtkViewNode', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js index c188a53f45d..dc703ecca80 100644 --- a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js +++ b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js @@ -68,7 +68,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkViewNodeFactory'); +export const newInstance = macro.newInstance( + extend, + 'vtkViewNodeFactory', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/Actor/index.js b/Sources/Rendering/WebGPU/Actor/index.js index 13932ae6125..be47e4b7011 100644 --- a/Sources/Rendering/WebGPU/Actor/index.js +++ b/Sources/Rendering/WebGPU/Actor/index.js @@ -186,7 +186,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/Camera/index.js b/Sources/Rendering/WebGPU/Camera/index.js index c447c65f05b..3dcfb0c055b 100644 --- a/Sources/Rendering/WebGPU/Camera/index.js +++ b/Sources/Rendering/WebGPU/Camera/index.js @@ -164,7 +164,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js index ba9ef4cc8d2..5577dc79518 100644 --- a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js @@ -147,7 +147,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkWebGPUHardwareSelectionPass' + 'vtkWebGPUHardwareSelectionPass', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/HardwareSelector/index.js b/Sources/Rendering/WebGPU/HardwareSelector/index.js index b159bf45ac3..c73830208f3 100644 --- a/Sources/Rendering/WebGPU/HardwareSelector/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelector/index.js @@ -443,7 +443,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkWebGPUHardwareSelector' + 'vtkWebGPUHardwareSelector', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/RenderWindow/index.js b/Sources/Rendering/WebGPU/RenderWindow/index.js index 2846a2be2e0..ca0252aaf44 100644 --- a/Sources/Rendering/WebGPU/RenderWindow/index.js +++ b/Sources/Rendering/WebGPU/RenderWindow/index.js @@ -634,7 +634,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkWebGPURenderWindow'); +export const newInstance = macro.newInstance( + extend, + 'vtkWebGPURenderWindow', + true +); // ---------------------------------------------------------------------------- // Register API specific RenderWindow implementation diff --git a/Sources/Rendering/WebGPU/Renderer/index.js b/Sources/Rendering/WebGPU/Renderer/index.js index e3d9097d087..9bef9bd21a4 100644 --- a/Sources/Rendering/WebGPU/Renderer/index.js +++ b/Sources/Rendering/WebGPU/Renderer/index.js @@ -367,7 +367,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkWebGPURenderer'); +export const newInstance = macro.newInstance(extend, 'vtkWebGPURenderer', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/ShaderCache/index.js b/Sources/Rendering/WebGPU/ShaderCache/index.js index 1d9fdce769e..6a21632ec2c 100644 --- a/Sources/Rendering/WebGPU/ShaderCache/index.js +++ b/Sources/Rendering/WebGPU/ShaderCache/index.js @@ -79,7 +79,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkWebGPUShaderCache'); +export const newInstance = macro.newInstance( + extend, + 'vtkWebGPUShaderCache', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js index db4ffca4445..1bf7c86784d 100644 --- a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js +++ b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js @@ -43,7 +43,8 @@ export function extend(publicAPI, model, initialValues = {}) { export const newInstance = macro.newInstance( extend, - 'vtkWebGPUViewNodeFactory' + 'vtkWebGPUViewNodeFactory', + true ); // ---------------------------------------------------------------------------- diff --git a/Sources/macros.js b/Sources/macros.js index e4977e12b0f..656eb805de7 100644 --- a/Sources/macros.js +++ b/Sources/macros.js @@ -969,12 +969,12 @@ export function event(publicAPI, model, eventName) { // newInstance // ---------------------------------------------------------------------------- -export function newInstance(extend, className) { - const constructor = (initialValues = {}) => { +export function newInstance(extend, className, toSet = false) { + const constructor = (initialValues = {}, toSetWhenVtkCalled = false) => { const model = {}; const publicAPI = {}; extend(publicAPI, model, initialValues); - publicAPI.set(initialValues, true); + if (toSet || toSetWhenVtkCalled) publicAPI.set(initialValues, true); return Object.freeze(publicAPI); }; diff --git a/Sources/vtk.js b/Sources/vtk.js index e2499df60a5..cc3bbc80001 100644 --- a/Sources/vtk.js +++ b/Sources/vtk.js @@ -44,7 +44,7 @@ export default function vtk(obj) { }); // Return the root - const newInst = constructor(model); + const newInst = constructor(model, true); if (newInst && newInst.modified) { newInst.modified(); } From ea30a9095d486529d684381f6237220c607a1f17 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 09:30:51 +0200 Subject: [PATCH 18/36] fix(polydatamapper): fix refactoring fix refactoring --- .../Rendering/OpenGL/PolyDataMapper/index.js | 18 +++++++------ .../OpenGL/PolyDataMapper2D/index.js | 27 +++++++++++++------ .../Rendering/WebGPU/PolyDataMapper/index.js | 13 ++++----- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Sources/Rendering/OpenGL/PolyDataMapper/index.js b/Sources/Rendering/OpenGL/PolyDataMapper/index.js index 137ae2fbbc8..48aa092df31 100755 --- a/Sources/Rendering/OpenGL/PolyDataMapper/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper/index.js @@ -2027,14 +2027,16 @@ function defaultValues(initialValues) { context: null, VBOBuildString: null, - primitives: Object.keys(primTypes).map((primType) => - vtkHelper.newInstance({ - primitiveType: primTypes[primType], - lastLightComplexity: 0, - lastLightCount: 0, - lastSelectionPass: false, - }) - ), + primitives: Object.keys(primTypes) + .filter((primType) => primType !== 'Start' && primType !== 'End') + .map((primType) => + vtkHelper.newInstance({ + primitiveType: primTypes[primType], + lastLightComplexity: 0, + lastLightCount: 0, + lastSelectionPass: false, + }) + ), primTypes, shaderRebuildString: null, diff --git a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js index fda5a4eb8e5..3bd42114664 100644 --- a/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js +++ b/Sources/Rendering/OpenGL/PolyDataMapper2D/index.js @@ -30,14 +30,16 @@ const EndEvent = { type: 'EndEvent' }; function defaultValues(initialValues) { return { // Internal Objects - primitives: Object.keys(primTypes).map((primType) => - vtkHelper.newInstance({ - primitiveType: primTypes[primType], - lastLightComplexity: 0, - lastLightCount: 0, - lastSelectionPass: false, - }) - ), + primitives: Object.keys(primTypes) + .filter((primType) => primType !== 'Start' && primType !== 'End') + .map((primType) => + vtkHelper.newInstance({ + primitiveType: primTypes[primType], + lastLightComplexity: 0, + lastLightCount: 0, + lastSelectionPass: false, + }) + ), primTypes, tmpMat4: mat4.identity(new Float64Array(16)), VBOBuildTime: macro.obj({}, { mtime: 0 }), @@ -758,6 +760,15 @@ export function extend(publicAPI, model, initialValues = {}) { initialValues ); + for (let i = primTypes.Start; i < primTypes.End; i++) { + initialValues.primitives[i] = vtkHelper.newInstance({ + primitiveType: i, + lastLightComplexity: 0, + lastLightCount: 0, + lastSelectionPass: false, + }); + } + // Build VTK API macro.setGet(publicAPI, model, ['context']); diff --git a/Sources/Rendering/WebGPU/PolyDataMapper/index.js b/Sources/Rendering/WebGPU/PolyDataMapper/index.js index 2047f8ef190..75f6bc844d1 100644 --- a/Sources/Rendering/WebGPU/PolyDataMapper/index.js +++ b/Sources/Rendering/WebGPU/PolyDataMapper/index.js @@ -96,20 +96,21 @@ function vtkWebGPUPolyDataMapper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - primitives: null, -}; +function defaultValues(initialValues) { + return { + primitives: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.primitives = []; - // Object methods vtkWebGPUPolyDataMapper(publicAPI, model); } From 141eb1f8a5ddf721f9d6ce15cd4fb2f77c013582 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 09:54:10 +0200 Subject: [PATCH 19/36] refactor(helper): refactor constructor to call setters refactor constructor to call setters --- Sources/Rendering/OpenGL/Helper/index.js | 39 +++++++++++------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Sources/Rendering/OpenGL/Helper/index.js b/Sources/Rendering/OpenGL/Helper/index.js index ec03a1ec322..1a202cc4cd0 100644 --- a/Sources/Rendering/OpenGL/Helper/index.js +++ b/Sources/Rendering/OpenGL/Helper/index.js @@ -259,31 +259,30 @@ function vtkOpenGLHelper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - context: null, - program: null, - shaderSourceTime: null, - VAO: null, - attributeUpdateTime: null, - CABO: null, - primitiveType: 0, - pointPicking: false, -}; +function defaultValues(initialValues) { + return { + // Internal objects + shaderSourceTime: macro.obj({}), + attributeUpdateTime: macro.obj({}), + + context: null, + program: vtkShaderProgram.newInstance(), + VAO: vtkVertexArrayObject.newInstance(), + CABO: vtkCellArrayBufferObject.newInstance(), + primitiveType: 0, + pointPicking: false, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); - model.shaderSourceTime = {}; - macro.obj(model.shaderSourceTime); - - model.attributeUpdateTime = {}; - macro.obj(model.attributeUpdateTime); - macro.setGet(publicAPI, model, [ 'program', 'shaderSourceTime', @@ -294,17 +293,13 @@ export function extend(publicAPI, model, initialValues = {}) { 'pointPicking', ]); - model.program = vtkShaderProgram.newInstance(); - model.VAO = vtkVertexArrayObject.newInstance(); - model.CABO = vtkCellArrayBufferObject.newInstance(); - // Object methods vtkOpenGLHelper(publicAPI, model); } // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend); +export const newInstance = macro.newInstance(extend, undefined, true); // ---------------------------------------------------------------------------- From 531eb9aca55da354f4852332b0b13d7f87006bd2 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 10:02:25 +0200 Subject: [PATCH 20/36] fix(testactor2d): remove .only( remove .only --- Sources/Rendering/Core/Actor2D/test/testActor2D.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Rendering/Core/Actor2D/test/testActor2D.js b/Sources/Rendering/Core/Actor2D/test/testActor2D.js index a6fff819048..2c0dbe27da5 100644 --- a/Sources/Rendering/Core/Actor2D/test/testActor2D.js +++ b/Sources/Rendering/Core/Actor2D/test/testActor2D.js @@ -16,7 +16,7 @@ import { Representation } from 'vtk.js/Sources/Rendering/Core/Property/Constants import baseline from './testActor2D.png'; -test.only('Test Actor2D', (t) => { +test('Test Actor2D', (t) => { const gc = testUtils.createGarbageCollector(t); t.ok('rendering', 'vtkActor2D'); From 01407f93bcfde48abad986c0871a199e43d9a35b Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 13:49:12 +0200 Subject: [PATCH 21/36] refactor(volume, texture): refactor constructor to call setters refactor constructor to call setters --- Sources/Rendering/Core/Volume/index.js | 24 ++--- Sources/Rendering/Core/VolumeMapper/index.js | 41 +++++---- Sources/Rendering/OpenGL/Texture/index.js | 65 +++++++------ Sources/Rendering/OpenGL/Volume/index.js | 27 +++--- .../Rendering/OpenGL/VolumeMapper/index.js | 92 +++++++++---------- 5 files changed, 122 insertions(+), 127 deletions(-) diff --git a/Sources/Rendering/Core/Volume/index.js b/Sources/Rendering/Core/Volume/index.js index 420322b02b3..717ddb1dba2 100644 --- a/Sources/Rendering/Core/Volume/index.js +++ b/Sources/Rendering/Core/Volume/index.js @@ -110,24 +110,26 @@ function vtkVolume(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - mapper: null, - property: null, - bounds: [1, -1, 1, -1, 1, -1], -}; +function defaultValues(initialValues) { + return { + // Internal objects + boundsMTime: macro.obj({}), + + mapper: null, + property: null, + bounds: [1, -1, 1, -1, 1, -1], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkProp3D.extend(publicAPI, model, initialValues); - // vtkTimeStamp - model.boundsMTime = {}; - macro.obj(model.boundsMTime); - // Build VTK API macro.set(publicAPI, model, ['property']); macro.setGet(publicAPI, model, ['mapper']); @@ -139,7 +141,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkVolume'); +export const newInstance = macro.newInstance(extend, 'vtkVolume', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/VolumeMapper/index.js b/Sources/Rendering/Core/VolumeMapper/index.js index 900bec718c8..244b47777e2 100644 --- a/Sources/Rendering/Core/VolumeMapper/index.js +++ b/Sources/Rendering/Core/VolumeMapper/index.js @@ -100,28 +100,31 @@ function vtkVolumeMapper(publicAPI, model) { // ---------------------------------------------------------------------------- // TODO: what values to use for averageIPScalarRange to get GLSL to use max / min values like [-Math.inf, Math.inf]? -const DEFAULT_VALUES = { - bounds: [1, -1, 1, -1, 1, -1], - sampleDistance: 1.0, - imageSampleDistance: 1.0, - maximumSamplesPerRay: 1000, - autoAdjustSampleDistances: true, - blendMode: BlendMode.COMPOSITE_BLEND, - ipScalarRange: [-1000000.0, 1000000.0], - filterMode: FilterMode.OFF, // ignored by WebGL so no behavior change - preferSizeOverAccuracy: false, // Whether to use halfFloat representation of float, when it is inaccurate - computeNormalFromOpacity: false, - // volume shadow parameters - volumetricScatteringBlending: 0.0, - globalIlluminationReach: 0.0, - volumeShadowSamplingDistFactor: 5.0, - anisotropy: 0.0, -}; +function defaultValues(initialValues) { + return { + bounds: [1, -1, 1, -1, 1, -1], + sampleDistance: 1.0, + imageSampleDistance: 1.0, + maximumSamplesPerRay: 1000, + autoAdjustSampleDistances: true, + blendMode: BlendMode.COMPOSITE_BLEND, + ipScalarRange: [-1000000.0, 1000000.0], + filterMode: FilterMode.OFF, // ignored by WebGL so no behavior change + preferSizeOverAccuracy: false, // Whether to use halfFloat representation of float, when it is inaccurate + computeNormalFromOpacity: false, + // volume shadow parameters + volumetricScatteringBlending: 0.0, + globalIlluminationReach: 0.0, + volumeShadowSamplingDistFactor: 5.0, + anisotropy: 0.0, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); vtkAbstractMapper.extend(publicAPI, model, initialValues); @@ -150,7 +153,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkVolumeMapper'); +export const newInstance = macro.newInstance(extend, 'vtkVolumeMapper', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/Texture/index.js b/Sources/Rendering/OpenGL/Texture/index.js index 3a21f0c05c8..30b8dc30a30 100644 --- a/Sources/Rendering/OpenGL/Texture/index.js +++ b/Sources/Rendering/OpenGL/Texture/index.js @@ -1463,47 +1463,46 @@ function vtkOpenGLTexture(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - _openGLRenderWindow: null, - context: null, - handle: 0, - sendParametersTime: null, - textureBuildTime: null, - numberOfDimensions: 0, - target: 0, - format: 0, - openGLDataType: 0, - components: 0, - width: 0, - height: 0, - depth: 0, - autoParameters: true, - wrapS: Wrap.CLAMP_TO_EDGE, - wrapT: Wrap.CLAMP_TO_EDGE, - wrapR: Wrap.CLAMP_TO_EDGE, - minificationFilter: Filter.NEAREST, - magnificationFilter: Filter.NEAREST, - minLOD: -1000.0, - maxLOD: 1000.0, - baseLevel: 0, - maxLevel: 1000, - generateMipmap: false, -}; +function defaultValues(initialValues) { + return { + // Internal objects + sendParametersTime: macro.obj({}, { mtime: 0 }), + textureBuildTime: macro.obj({}, { mtime: 0 }), + + _openGLRenderWindow: null, + context: null, + handle: 0, + numberOfDimensions: 0, + target: 0, + format: 0, + openGLDataType: 0, + components: 0, + width: 0, + height: 0, + depth: 0, + autoParameters: true, + wrapS: Wrap.CLAMP_TO_EDGE, + wrapT: Wrap.CLAMP_TO_EDGE, + wrapR: Wrap.CLAMP_TO_EDGE, + minificationFilter: Filter.NEAREST, + magnificationFilter: Filter.NEAREST, + minLOD: -1000.0, + maxLOD: 1000.0, + baseLevel: 0, + maxLevel: 1000, + generateMipmap: false, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.sendParametersTime = {}; - macro.obj(model.sendParametersTime, { mtime: 0 }); - - model.textureBuildTime = {}; - macro.obj(model.textureBuildTime, { mtime: 0 }); - // Build VTK API macro.set(publicAPI, model, ['format', 'openGLDataType']); diff --git a/Sources/Rendering/OpenGL/Volume/index.js b/Sources/Rendering/OpenGL/Volume/index.js index 83e6e0ea654..8a11ea722ad 100644 --- a/Sources/Rendering/OpenGL/Volume/index.js +++ b/Sources/Rendering/OpenGL/Volume/index.js @@ -89,28 +89,25 @@ function vtkOpenGLVolume(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - // context: null, - // keyMatrixTime: null, - // normalMatrix: null, - // MCWCMatrix: null, - // _openGLRenderWindow: null, -}; +function defaultValues(initialValues) { + return { + // context: null, + keyMatrixTime: macro.obj({}, { mtime: 0 }), + normalMatrix: new Float64Array(9), + MCWCMatrix: new Float64Array(16), + // _openGLRenderWindow: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.keyMatrixTime = {}; - macro.obj(model.keyMatrixTime, { mtime: 0 }); - // always set by getter - model.normalMatrix = new Float64Array(9); - model.MCWCMatrix = new Float64Array(16); - // Build VTK API macro.setGet(publicAPI, model, ['context']); @@ -120,7 +117,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLVolume'); +export const newInstance = macro.newInstance(extend, 'vtkOpenGLVolume', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/VolumeMapper/index.js b/Sources/Rendering/OpenGL/VolumeMapper/index.js index 2107ccb71f5..91c751f5a1a 100644 --- a/Sources/Rendering/OpenGL/VolumeMapper/index.js +++ b/Sources/Rendering/OpenGL/VolumeMapper/index.js @@ -1528,62 +1528,52 @@ function vtkOpenGLVolumeMapper(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - context: null, - VBOBuildTime: null, - scalarTexture: null, - scalarTextureString: null, - opacityTexture: null, - opacityTextureString: null, - colorTexture: null, - colorTextureString: null, - jitterTexture: null, - tris: null, - framebuffer: null, - copyShader: null, - copyVAO: null, - lastXYF: 1.0, - targetXYF: 1.0, - zBufferTexture: null, - lastZBufferTexture: null, - lastLightComplexity: 0, - fullViewportTime: 1.0, - idxToView: null, - idxNormalMatrix: null, - modelToView: null, - projectionToView: null, - avgWindowArea: 0.0, - avgFrameTime: 0.0, -}; +function defaultValues(initialValues) { + return { + // Internal Objects + VBOBuildTime: macro.obj({}, { mtime: 0 }), + tris: vtkHelper.newInstance(), + scalarTexture: vtkOpenGLTexture.newInstance(), + opacityTexture: vtkOpenGLTexture.newInstance(), + colorTexture: vtkOpenGLTexture.newInstance(), + jitterTexture: vtkOpenGLTexture.newInstance({ + wrapS: Wrap.REPEAT, + wrapT: Wrap.REPEAT, + }), + framebuffer: vtkOpenGLFramebuffer.newInstance(), + idxToView: mat4.identity(new Float64Array(16)), + idxNormalMatrix: mat3.identity(new Float64Array(9)), + modelToView: mat4.identity(new Float64Array(16)), + projectionToView: mat4.identity(new Float64Array(16)), + projectionToWorld: mat4.identity(new Float64Array(16)), + _lastScale: 1.0, + + context: null, + scalarTextureString: null, + opacityTextureString: null, + colorTextureString: null, + copyShader: null, + copyVAO: null, + lastXYF: 1.0, + targetXYF: 1.0, + zBufferTexture: null, + lastZBufferTexture: null, + lastLightComplexity: 0, + fullViewportTime: 1.0, + avgWindowArea: 0.0, + avgFrameTime: 0.0, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - model.VBOBuildTime = {}; - macro.obj(model.VBOBuildTime, { mtime: 0 }); - - model.tris = vtkHelper.newInstance(); - model.scalarTexture = vtkOpenGLTexture.newInstance(); - model.opacityTexture = vtkOpenGLTexture.newInstance(); - model.colorTexture = vtkOpenGLTexture.newInstance(); - model.jitterTexture = vtkOpenGLTexture.newInstance(); - model.jitterTexture.setWrapS(Wrap.REPEAT); - model.jitterTexture.setWrapT(Wrap.REPEAT); - model.framebuffer = vtkOpenGLFramebuffer.newInstance(); - - model.idxToView = mat4.identity(new Float64Array(16)); - model.idxNormalMatrix = mat3.identity(new Float64Array(9)); - model.modelToView = mat4.identity(new Float64Array(16)); - model.projectionToView = mat4.identity(new Float64Array(16)); - model.projectionToWorld = mat4.identity(new Float64Array(16)); - - model._lastScale = 1.0; - // Build VTK API macro.setGet(publicAPI, model, ['context']); @@ -1593,7 +1583,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLVolumeMapper'); +export const newInstance = macro.newInstance( + extend, + 'vtkOpenGLVolumeMapper', + true +); // ---------------------------------------------------------------------------- From 12c88ab5b34f9f853aa9be08490d7a5c47b00808 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 14:08:03 +0200 Subject: [PATCH 22/36] refactor(sources): refactoring constructors some more sources refactoring --- .../Sources/ConcentricCylinderSource/index.js | 13 ++++++-- Sources/Filters/Sources/PointSource/index.js | 19 +++++++----- .../Filters/Sources/RTAnalyticSource/index.js | 31 ++++++++++++------- Sources/Filters/Sources/SLICSource/index.js | 23 ++++++++------ .../Filters/Sources/ViewFinderSource/index.js | 26 +++++++++------- 5 files changed, 68 insertions(+), 44 deletions(-) diff --git a/Sources/Filters/Sources/ConcentricCylinderSource/index.js b/Sources/Filters/Sources/ConcentricCylinderSource/index.js index c69584ccc86..a442c2a8d89 100644 --- a/Sources/Filters/Sources/ConcentricCylinderSource/index.js +++ b/Sources/Filters/Sources/ConcentricCylinderSource/index.js @@ -35,9 +35,16 @@ function vtkConcentricCylinderSource(publicAPI, model) { publicAPI.getNumberOfRadius = () => model.radius.length; publicAPI.getRadius = (index = 0) => model.radius[index]; - publicAPI.setRadius = (index, radius) => { - if (!model.radius) model.radius = []; - model.radius[index] = radius; + publicAPI.setRadius = (...args) => { + // Handle instanciation time + let n = []; + + if (args.length === 1 || Array.isArray(args[0])) { + n = [...args[0]]; + model.radius = n; + } else if (args.length === 2) { + model.radius[args[0]] = args[1]; + } publicAPI.modified(); }; publicAPI.setCellField = (index, field) => { diff --git a/Sources/Filters/Sources/PointSource/index.js b/Sources/Filters/Sources/PointSource/index.js index 85f22684316..a0131e2077c 100644 --- a/Sources/Filters/Sources/PointSource/index.js +++ b/Sources/Filters/Sources/PointSource/index.js @@ -66,17 +66,20 @@ function vtkPointSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - numberOfPoints: 10, - center: [0, 0, 0], - radius: 0.5, - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + numberOfPoints: 10, + center: [0, 0, 0], + radius: 0.5, + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -88,7 +91,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkPointSource'); +export const newInstance = macro.newInstance(extend, 'vtkPointSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/RTAnalyticSource/index.js b/Sources/Filters/Sources/RTAnalyticSource/index.js index 3ff7cbc0279..bb70cd90397 100644 --- a/Sources/Filters/Sources/RTAnalyticSource/index.js +++ b/Sources/Filters/Sources/RTAnalyticSource/index.js @@ -103,21 +103,24 @@ function vtkRTAnalyticSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - offset: 40, - maximum: 120, - center: [0, 0, 0], - frequency: [60, 30, 40], - magnitude: [10, 18, 5], - standardDeviation: 0.5, - wholeExtent: [-10, 10, -10, 10, -10, 10], - dataDirection: [1, 0, 0, 0, 1, 0, 0, 0, 1], -}; +function defaultValues(initialValues) { + return { + offset: 40, + maximum: 120, + center: [0, 0, 0], + frequency: [60, 30, 40], + magnitude: [10, 18, 5], + standardDeviation: 0.5, + wholeExtent: [-10, 10, -10, 10, -10, 10], + dataDirection: [1, 0, 0, 0, 1, 0, 0, 0, 1], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -136,7 +139,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkRTAnalyticSource'); +export const newInstance = macro.newInstance( + extend, + 'vtkRTAnalyticSource', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/SLICSource/index.js b/Sources/Filters/Sources/SLICSource/index.js index fbe88ed700c..532b79f0769 100644 --- a/Sources/Filters/Sources/SLICSource/index.js +++ b/Sources/Filters/Sources/SLICSource/index.js @@ -176,19 +176,22 @@ function vtkSLICSource(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - clusters: [], - spacing: [1.0, 1.0, 1.0], - origin: [0.0, 0.0, 0.0], - dimensions: [10, 10, 10], - clusterArrayName: 'cluster', - scalarArrayName: 'field', -}; +function defaultValues(initialValues) { + return { + clusters: [], + spacing: [1.0, 1.0, 1.0], + origin: [0.0, 0.0, 0.0], + dimensions: [10, 10, 10], + clusterArrayName: 'cluster', + scalarArrayName: 'field', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -202,7 +205,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkSLICSource'); +export const newInstance = macro.newInstance(extend, 'vtkSLICSource', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Filters/Sources/ViewFinderSource/index.js b/Sources/Filters/Sources/ViewFinderSource/index.js index 873c238391a..01eb8e2940c 100644 --- a/Sources/Filters/Sources/ViewFinderSource/index.js +++ b/Sources/Filters/Sources/ViewFinderSource/index.js @@ -92,20 +92,24 @@ function vtkViewFinderSource(publicAPI, model) { // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - radius: 1, - spacing: 2, - width: 4, - pointType: 'Float64Array', -}; +function defaultValues(initialValues) { + return { + //Internal + center: [0, 0, 0], + orientation: [1, 0, 0], + + radius: 1, + spacing: 2, + width: 4, + pointType: 'Float64Array', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - model.center = [0, 0, 0]; - model.orientation = [1, 0, 0]; - - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -117,7 +121,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkArrow2DSource'); +export const newInstance = macro.newInstance(extend, 'vtkArrow2DSource', true); // ---------------------------------------------------------------------------- From 1bb1060250b518329e20abd28f0afbfca2c91953 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 14:24:49 +0200 Subject: [PATCH 23/36] test(points): add some tests for points add some tests for points (similar to dataarray tests) --- Sources/Common/Core/Points/test/testPoints.js | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Sources/Common/Core/Points/test/testPoints.js diff --git a/Sources/Common/Core/Points/test/testPoints.js b/Sources/Common/Core/Points/test/testPoints.js new file mode 100644 index 00000000000..4825c2c5c62 --- /dev/null +++ b/Sources/Common/Core/Points/test/testPoints.js @@ -0,0 +1,130 @@ +import test from 'tape-catch'; +import vtkPoints from 'vtk.js/Sources/Common/Core/Points'; +import Constants from 'vtk.js/Sources/Common/Core/DataArray/Constants'; +import * as macro from 'vtk.js/Sources/macros'; + +const { DefaultDataType } = Constants; + +function getPointsProperties(points) { + return { + size: points.get().size, + numberOfComponents: points.get().numberOfComponents, + dataType: points.get().dataType, + values: points.get().values, + }; +} + +test('Test vtkPoints instance', (t) => { + t.ok(vtkPoints, 'Make sure the class definition exists'); + + t.doesNotThrow( + () => vtkPoints.newInstance({ size: 256 }), + 'Allowed to create instance with only size' + ); + + const points0 = vtkPoints.newInstance({ + empty: true, + values: null, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 3, + values: null, + }, + getPointsProperties(points0), + 'initialValues.values = null' + ); + + const points1 = vtkPoints.newInstance({ size: 3 }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 3, + values: macro.newTypedArray(DefaultDataType, 3), + }, + getPointsProperties(points1), + 'Give only size to create instance' + ); + + const points2 = vtkPoints.newInstance({ + values: Uint32Array.from([1, 2, 3]), + }); + t.deepEqual( + { + dataType: 'Uint32Array', + size: 3, + numberOfComponents: 3, + values: Uint32Array.from([1, 2, 3]), + }, + getPointsProperties(points2), + 'Create instance with data (typed array)' + ); + + const points3 = vtkPoints.newInstance({ + values: [1, 2, 3], + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 3, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3]), + }, + getPointsProperties(points3), + 'Create instance with data (untyped array)' + ); + + const points4 = vtkPoints.newInstance({ + values: [1, 2, 3, 4, 5, 6, 7, 8, 9], + numberOfComponents: 3, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 9, + numberOfComponents: 3, + values: macro.newTypedArrayFrom( + DefaultDataType, + [1, 2, 3, 4, 5, 6, 7, 8, 9] + ), + }, + getPointsProperties(points4), + 'Change number of components at instanciation' + ); + + const points5 = vtkPoints.newInstance({ + values: [1, 2, 3], + dataType: null, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 3, + numberOfComponents: 3, + values: macro.newTypedArrayFrom(DefaultDataType, [1, 2, 3]), + }, + getPointsProperties(points5), + 'Give null as dataType' + ); + + const points6 = vtkPoints.newInstance({ + empty: true, + values: null, + numberOfComponents: 3, + }); + t.deepEqual( + { + dataType: DefaultDataType, + size: 0, + numberOfComponents: 3, + values: null, + }, + getPointsProperties(points6), + 'Give numberOfComponents!=1 with empty array' + ); + + t.end(); +}); From 9b571dbcd721bb1dd91ab818b9453ac04240a0c7 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 14:49:03 +0200 Subject: [PATCH 24/36] refactor(stringarray,variantarray,progresshandler,priorityqueue): refactor constructors refactor constructors to call setters. Change setData to handle instanciation and setting --- Sources/Common/Core/PriorityQueue/index.js | 13 ++-- Sources/Common/Core/ProgressHandler/index.js | 17 +++-- Sources/Common/Core/StringArray/index.js | 72 +++++++++++++------- Sources/Common/Core/VariantArray/index.js | 72 +++++++++++++------- 4 files changed, 116 insertions(+), 58 deletions(-) diff --git a/Sources/Common/Core/PriorityQueue/index.js b/Sources/Common/Core/PriorityQueue/index.js index ed22e222e00..156e7f9ca16 100644 --- a/Sources/Common/Core/PriorityQueue/index.js +++ b/Sources/Common/Core/PriorityQueue/index.js @@ -34,14 +34,17 @@ function vtkPriorityQueue(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - elements: [], -}; +function defaultValues(initialValues) { + return { + elements: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); @@ -50,7 +53,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkPriorityQueue'); +export const newInstance = macro.newInstance(extend, 'vtkPriorityQueue', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/ProgressHandler/index.js b/Sources/Common/Core/ProgressHandler/index.js index d0a4ea757a5..423a8899f09 100644 --- a/Sources/Common/Core/ProgressHandler/index.js +++ b/Sources/Common/Core/ProgressHandler/index.js @@ -50,14 +50,17 @@ function vtkProgressHandler(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - workCount: 0, -}; +function defaultValues(initialValues) { + return { + workCount: 0, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); @@ -70,7 +73,11 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkProgressHandler'); +export const newInstance = macro.newInstance( + extend, + 'vtkProgressHandler', + true +); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/StringArray/index.js b/Sources/Common/Core/StringArray/index.js index 0ec1533f4bb..639ab08175c 100644 --- a/Sources/Common/Core/StringArray/index.js +++ b/Sources/Common/Core/StringArray/index.js @@ -66,8 +66,14 @@ function vtkStringArray(publicAPI, model) { }; publicAPI.setData = (array, numberOfComponents) => { + if (Array.isArray(array)) { + // eslint-disable-next-line no-param-reassign + array = macro.newTypedArrayFrom(model.dataType, array); + } + model.values = array; - model.size = array.length; + model.size = array ? array.length : 0; + if (numberOfComponents) { model.numberOfComponents = numberOfComponents; } @@ -82,46 +88,64 @@ function vtkStringArray(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - name: '', - numberOfComponents: 1, - size: 0, - // values: null, - dataType: 'string', -}; +function defaultValues(initialValues) { + return { + name: '', + numberOfComponents: 1, + size: 0, + // values: null, + dataType: 'string', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - - if (!model.empty && !model.values && !model.size) { + if (!initialValues.empty && !initialValues.values && !initialValues.size) { throw new TypeError( - 'Cannot create vtkStringArray object without: size > 0, values' + 'Cannot create vtkDataArray object without: size > 0, values' ); } - - if (!model.values) { - model.values = []; - } else if (Array.isArray(model.values)) { - model.values = [...model.values]; - } - - if (model.values) { - model.size = model.values.length; - } + delete initialValues.empty; + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); - macro.set(publicAPI, model, ['name']); + macro.set(publicAPI, model, ['name', 'numberOfComponents']); + + model.dataType = initialValues.dataType ? initialValues.dataType : 'string'; + delete initialValues.dataType; + if (!initialValues.values) { + if (!initialValues.size) initialValues.values = null; + else + initialValues.values = macro.newTypedArray( + model.dataType, + initialValues.size + ); + } else if (Array.isArray(initialValues.values)) { + initialValues.values = macro.newTypedArrayFrom( + model.dataType, + initialValues.values + ); + } // Object specific methods vtkStringArray(publicAPI, model); + + // We call customly setData here to keep coherence between parameters before + // the call of publicAPI.set(initialValues) in the constructor + // Warning : setData cannot be overwritten in a child class + publicAPI.setData(initialValues.values, initialValues.numberOfComponents); + delete initialValues.values; + delete initialValues.dataType; + delete initialValues.numberOfComponents; + delete initialValues.size; } // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkStringArray'); +export const newInstance = macro.newInstance(extend, 'vtkStringArray', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/Core/VariantArray/index.js b/Sources/Common/Core/VariantArray/index.js index 38b12c8dd17..7795aa1a46a 100644 --- a/Sources/Common/Core/VariantArray/index.js +++ b/Sources/Common/Core/VariantArray/index.js @@ -66,8 +66,14 @@ function vtkVariantArray(publicAPI, model) { }; publicAPI.setData = (array, numberOfComponents) => { + if (Array.isArray(array)) { + // eslint-disable-next-line no-param-reassign + array = macro.newTypedArrayFrom(model.dataType, array); + } + model.values = array; - model.size = array.length; + model.size = array ? array.length : 0; + if (numberOfComponents) { model.numberOfComponents = numberOfComponents; } @@ -82,46 +88,64 @@ function vtkVariantArray(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - name: '', - numberOfComponents: 1, - size: 0, - // values: null, - dataType: 'JSON', -}; +function defaultValues(initialValues) { + return { + name: '', + numberOfComponents: 1, + size: 0, + // values: null, + dataType: 'JSON', + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); - - if (!model.empty && !model.values && !model.size) { + if (!initialValues.empty && !initialValues.values && !initialValues.size) { throw new TypeError( - 'Cannot create vtkVariantArray object without: size > 0, values' + 'Cannot create vtkDataArray object without: size > 0, values' ); } - - if (!model.values) { - model.values = []; - } else if (Array.isArray(model.values)) { - model.values = [...model.values]; - } - - if (model.values) { - model.size = model.values.length; - } + delete initialValues.empty; + Object.assign(initialValues, defaultValues(initialValues)); // Object methods macro.obj(publicAPI, model); - macro.set(publicAPI, model, ['name']); + macro.set(publicAPI, model, ['name', 'numberOfComponents']); + + model.dataType = initialValues.dataType ? initialValues.dataType : 'JSON'; + delete initialValues.dataType; + if (!initialValues.values) { + if (!initialValues.size) initialValues.values = null; + else + initialValues.values = macro.newTypedArray( + model.dataType, + initialValues.size + ); + } else if (Array.isArray(initialValues.values)) { + initialValues.values = macro.newTypedArrayFrom( + model.dataType, + initialValues.values + ); + } // Object specific methods vtkVariantArray(publicAPI, model); + + // We call customly setData here to keep coherence between parameters before + // the call of publicAPI.set(initialValues) in the constructor + // Warning : setData cannot be overwritten in a child class + publicAPI.setData(initialValues.values, initialValues.numberOfComponents); + delete initialValues.values; + delete initialValues.dataType; + delete initialValues.numberOfComponents; + delete initialValues.size; } // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkVariantArray'); +export const newInstance = macro.newInstance(extend, 'vtkVariantArray', true); // ---------------------------------------------------------------------------- From afb7f8672630ef9784726113f735a519d460586f Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 15:07:44 +0200 Subject: [PATCH 25/36] fix(lookuptable): fix refactoring fix refactoring (put table in defaultValues) --- Sources/Common/Core/LookupTable/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index 0d9a11e2b06..7d9d1424545 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -303,6 +303,7 @@ function vtkLookupTable(publicAPI, model) { function defaultValues(initialValues) { return { // Internal objects + table: [], buildTime: macro.obj({}), opaqueFlagBuildTime: macro.obj({}, { mtime: 0 }), insertTime: macro.obj({}, { mtime: 0 }), @@ -337,8 +338,9 @@ export function extend(publicAPI, model, initialValues = {}) { vtkScalarsToColors.extend(publicAPI, model, initialValues); // Internal objects initialization - if (!model.table) { - model.table = []; + if (Array.isArray(initialValues.table)) { + model.table = initialValues.table; + delete initialValues.table; } // Create get-only macros From 562a185b56ea7dcb7c41cc6e3636dc7c0867758a Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 15:15:24 +0200 Subject: [PATCH 26/36] refactor(cell): refactor constructor to call setters refactor constructor to call setters --- Sources/Common/DataModel/Cell/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Common/DataModel/Cell/index.js b/Sources/Common/DataModel/Cell/index.js index 43a821e4878..aa3a9b018f5 100644 --- a/Sources/Common/DataModel/Cell/index.js +++ b/Sources/Common/DataModel/Cell/index.js @@ -122,22 +122,22 @@ function vtkCell(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - bounds: [-1, -1, -1, -1, -1, -1], - pointsIds: [], -}; +function defaultValues(initialValues) { + return { + points: vtkPoints.newInstance(), + bounds: [-1, -1, -1, -1, -1, -1], + pointsIds: [], + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); macro.obj(publicAPI, model); - if (!model.points) { - model.points = vtkPoints.newInstance({ values: [] }); - } - macro.get(publicAPI, model, ['points', 'pointsIds']); vtkCell(publicAPI, model); @@ -145,7 +145,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkCell'); +export const newInstance = macro.newInstance(extend, 'vtkCell', true); // ---------------------------------------------------------------------------- From d2725c23e7c7420ef0bf969d350c24b682acf250 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 15:52:29 +0200 Subject: [PATCH 27/36] docs(lookuptable, appendpolydata): document some implementation choices document some implementation choices --- Sources/Common/Core/LookupTable/index.js | 2 ++ Sources/Filters/General/AppendPolyData/index.js | 1 + 2 files changed, 3 insertions(+) diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index 7d9d1424545..ba9d4391781 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -338,6 +338,8 @@ export function extend(publicAPI, model, initialValues = {}) { vtkScalarsToColors.extend(publicAPI, model, initialValues); // Internal objects initialization + // model.table needs to be instanciated manually if it is an array to not call + // setTable in that case if (Array.isArray(initialValues.table)) { model.table = initialValues.table; delete initialValues.table; diff --git a/Sources/Filters/General/AppendPolyData/index.js b/Sources/Filters/General/AppendPolyData/index.js index 1fa6145ac99..d5f34022534 100644 --- a/Sources/Filters/General/AppendPolyData/index.js +++ b/Sources/Filters/General/AppendPolyData/index.js @@ -10,6 +10,7 @@ const { vtkErrorMacro } = macro; function offsetCellArray(typedArray, offset) { let currentIdx = 0; + // No data to shift if (!typedArray) return {}; return typedArray.map((value, index) => { if (index === currentIdx) { From 7824f27cab98c751e8510e8bbd82e03548e5758d Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 16:30:11 +0200 Subject: [PATCH 28/36] fix(lookuptable): fix previous commit fix previous commit --- Sources/Common/Core/LookupTable/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Common/Core/LookupTable/index.js b/Sources/Common/Core/LookupTable/index.js index ba9d4391781..10e667b318c 100644 --- a/Sources/Common/Core/LookupTable/index.js +++ b/Sources/Common/Core/LookupTable/index.js @@ -389,7 +389,7 @@ export function extend(publicAPI, model, initialValues = {}) { if (initialValues.table && initialValues.table.length > 0) { // ensure insertTime is more recently modified than buildTime if // a table is provided via the constructor - model.insertTime.modified(); + initialValues.insertTime.modified(); } } From b14ebe2dc490b23720af3339170ba88b09e1a972 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:03:25 +0200 Subject: [PATCH 29/36] fix(abstractmapper, selectionnode): fix refactoring fix refactoring --- .../Common/DataModel/SelectionNode/index.js | 22 +++++++++---------- .../Rendering/Core/AbstractMapper/index.js | 6 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/Common/DataModel/SelectionNode/index.js b/Sources/Common/DataModel/SelectionNode/index.js index 99273d62d28..c6402405a58 100644 --- a/Sources/Common/DataModel/SelectionNode/index.js +++ b/Sources/Common/DataModel/SelectionNode/index.js @@ -1,6 +1,17 @@ import macro from 'vtk.js/Sources/macros'; import Constants from 'vtk.js/Sources/Common/DataModel/SelectionNode/Constants'; +// ---------------------------------------------------------------------------- +// vtkSelectionNode methods +// ---------------------------------------------------------------------------- + +function vtkSelectionNode(publicAPI, model) { + // Set our className + model.classHierarchy.push('vtkSelectionNode'); + + publicAPI.getBounds = () => model.points.getBounds(); +} + // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- @@ -14,17 +25,6 @@ function defaultValues(initialValues) { }; } -// ---------------------------------------------------------------------------- -// vtkSelectionNode methods -// ---------------------------------------------------------------------------- - -function vtkSelectionNode(publicAPI, model) { - // Set our className - model.classHierarchy.push('vtkSelectionNode'); - - publicAPI.getBounds = () => model.points.getBounds(); -} - // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/Core/AbstractMapper/index.js b/Sources/Rendering/Core/AbstractMapper/index.js index 73de89cd66a..ca683775e3a 100644 --- a/Sources/Rendering/Core/AbstractMapper/index.js +++ b/Sources/Rendering/Core/AbstractMapper/index.js @@ -22,8 +22,7 @@ function vtkAbstractMapper(publicAPI, model) { return false; }; - publicAPI.getNumberOfClippingPlanes = () => - model.clippingPlanes ? model.clippingPlanes.length : 0; + publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length; publicAPI.removeAllClippingPlanes = () => { model.clippingPlanes.length = 0; @@ -42,7 +41,8 @@ function vtkAbstractMapper(publicAPI, model) { publicAPI.getClippingPlanes = () => model.clippingPlanes; publicAPI.setClippingPlanes = (planes) => { - if (!planes || planes.length === 0) { + // Instanciation time + if (model.clippingPlanes === undefined) { model.clippingPlanes = []; return; } From ad468f28dd9e007dc37a67c162564491fe1c7d56 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:04:21 +0200 Subject: [PATCH 30/36] refactor(triangle, line): refactor constructors refactor constructors to call setters at instanciation --- Sources/Common/DataModel/Line/index.js | 10 +++++++--- Sources/Common/DataModel/Triangle/index.js | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Sources/Common/DataModel/Line/index.js b/Sources/Common/DataModel/Line/index.js index 54a1af94fbd..e9a233e6643 100644 --- a/Sources/Common/DataModel/Line/index.js +++ b/Sources/Common/DataModel/Line/index.js @@ -231,12 +231,16 @@ function vtkLine(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = {}; +function defaultValues(initialValues) { + return { + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); vtkCell.extend(publicAPI, model, initialValues); @@ -245,7 +249,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkLine'); +export const newInstance = macro.newInstance(extend, 'vtkLine', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Common/DataModel/Triangle/index.js b/Sources/Common/DataModel/Triangle/index.js index fb6e0b3080e..421af34237e 100644 --- a/Sources/Common/DataModel/Triangle/index.js +++ b/Sources/Common/DataModel/Triangle/index.js @@ -573,12 +573,15 @@ function vtkTriangle(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = {}; - +function defaultValues(initialValues) { + return { + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); vtkCell.extend(publicAPI, model, initialValues); @@ -587,7 +590,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkTriangle'); +export const newInstance = macro.newInstance(extend, 'vtkTriangle', true); // ---------------------------------------------------------------------------- From b74186e23451727ad302d71e1dc74c9ad8f4d73e Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:44:07 +0200 Subject: [PATCH 31/36] fix(camera): fix refactoring remove undesired checks and document some choices --- Sources/Rendering/Core/Camera/index.js | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/Rendering/Core/Camera/index.js b/Sources/Rendering/Core/Camera/index.js index a6f5720b4c7..82910aeb866 100644 --- a/Sources/Rendering/Core/Camera/index.js +++ b/Sources/Rendering/Core/Camera/index.js @@ -77,7 +77,6 @@ function vtkCamera(publicAPI, model) { // Internal Functions that don't need to be public function computeViewPlaneNormal() { - if (!model.viewPlaneNormal) model.viewPlaneNormal = [0, 0, 0]; // VPN is -DOP model.viewPlaneNormal[0] = -model.directionOfProjection[0]; model.viewPlaneNormal[1] = -model.directionOfProjection[1]; @@ -102,7 +101,8 @@ function vtkCamera(publicAPI, model) { ) { return; } - if (!model.position) { + // Instanciation time + if (model.position === undefined) { model.position = defaultValues().position; } @@ -124,7 +124,10 @@ function vtkCamera(publicAPI, model) { ) { return; } - + // Instanciation time + if (model.focalPoint === undefined) { + model.focalPoint = defaultValues().focalPoint; + } model.focalPoint[0] = x; model.focalPoint[1] = y; model.focalPoint[2] = z; @@ -159,10 +162,12 @@ function vtkCamera(publicAPI, model) { //---------------------------------------------------------------------------- // This method must be called when the focal point or camera position changes publicAPI.computeDistance = () => { - if (!model.position) { + // Instanciation time : computeDistance can be called either when model.position + // or model.focalPoint are undefined + if (model.position === undefined) { model.position = defaultValues().position; } - if (!model.focalPoint) { + if (model.focalPoint === undefined) { model.focalPoint = defaultValues().focalPoint; } const dx = model.focalPoint[0] - model.position[0]; @@ -171,7 +176,7 @@ function vtkCamera(publicAPI, model) { model.distance = Math.sqrt(dx * dx + dy * dy + dz * dz); - if (!model.directionOfProjection) { + if (model.directionOfProjection === undefined) { model.directionOfProjection = defaultValues().directionOfProjection; } @@ -233,7 +238,6 @@ function vtkCamera(publicAPI, model) { ); vec4.transformMat4(viewUpVec4, viewUpVec4, rotateMatrix); - if (!model.viewUp) model.viewUp = defaultValues().viewUp; model.viewUp[0] = viewUpVec4[0]; model.viewUp[1] = viewUpVec4[1]; model.viewUp[2] = viewUpVec4[2]; @@ -242,7 +246,7 @@ function vtkCamera(publicAPI, model) { }; publicAPI.azimuth = (angle) => { - const fp = model.focalPoint ? model.focalPoint : defaultValues().focalPoint; + const fp = model.focalPoint; mat4.identity(trans); @@ -250,13 +254,11 @@ function vtkCamera(publicAPI, model) { // rotate about view up, // translate back again mat4.translate(trans, trans, fp); - const viewUp = model.viewUp ? model.viewUp : defaultValues().viewUp; - mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), viewUp); + mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), model.viewUp); mat4.translate(trans, trans, [-fp[0], -fp[1], -fp[2]]); // apply the transform to the position - const pos = model.position ? model.position : defaultValues().position; - vec3.transformMat4(newPosition, pos, trans); + vec3.transformMat4(newPosition, model.position, trans); publicAPI.setPosition(newPosition[0], newPosition[1], newPosition[2]); }; @@ -736,9 +738,7 @@ function vtkCamera(publicAPI, model) { let vn = null; let position = null; - vn = model.viewPlaneNormal - ? model.viewPlaneNormal - : defaultValues().viewPlaneNormal; + vn = model.viewPlaneNormal; position = model.position; const a = -vn[0]; From d4def4653d365af6d6bfb7f862c2793e64141576 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:51:24 +0200 Subject: [PATCH 32/36] fix(camera): fix previous commit fix previous commit --- Sources/Rendering/Core/Camera/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Rendering/Core/Camera/index.js b/Sources/Rendering/Core/Camera/index.js index 82910aeb866..85cfae81f89 100644 --- a/Sources/Rendering/Core/Camera/index.js +++ b/Sources/Rendering/Core/Camera/index.js @@ -77,6 +77,10 @@ function vtkCamera(publicAPI, model) { // Internal Functions that don't need to be public function computeViewPlaneNormal() { + // Instanciation time + if (model.viewPlaneNormal === undefined) { + model.viewPlaneNormal = defaultValues().viewPlaneNormal; + } // VPN is -DOP model.viewPlaneNormal[0] = -model.directionOfProjection[0]; model.viewPlaneNormal[1] = -model.directionOfProjection[1]; From df6db6fb8772e8d6c442939e446b22de704bbd06 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:53:38 +0200 Subject: [PATCH 33/36] fix(coordinate, hardwareselector): fix refactoring fix refactoring --- Sources/Rendering/Core/Coordinate/index.js | 1 + .../Rendering/Core/HardwareSelector/index.js | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Sources/Rendering/Core/Coordinate/index.js b/Sources/Rendering/Core/Coordinate/index.js index 28363a2d69b..164df3a97e3 100644 --- a/Sources/Rendering/Core/Coordinate/index.js +++ b/Sources/Rendering/Core/Coordinate/index.js @@ -33,6 +33,7 @@ function vtkCoordinate(publicAPI, model) { throw new RangeError('Invalid number of values for array setter'); } let changeDetected = false; + // Instanciation time : if model.value is undefined, change needs to be done if (model.value) { model.value.forEach((item, index) => { if (item !== array[index]) { diff --git a/Sources/Rendering/Core/HardwareSelector/index.js b/Sources/Rendering/Core/HardwareSelector/index.js index db7b404a9d5..5326b8d8643 100644 --- a/Sources/Rendering/Core/HardwareSelector/index.js +++ b/Sources/Rendering/Core/HardwareSelector/index.js @@ -3,18 +3,6 @@ import vtkDataSet from 'vtk.js/Sources/Common/DataModel/DataSet'; const { FieldAssociations } = vtkDataSet; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - fieldAssociation: FieldAssociations.FIELD_ASSOCIATION_CELLS, - captureZValues: false, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkHardwareSelector methods // ---------------------------------------------------------------------------- @@ -43,6 +31,18 @@ function vtkHardwareSelector(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + fieldAssociation: FieldAssociations.FIELD_ASSOCIATION_CELLS, + captureZValues: false, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { From 114330ef39c1c3c3276ef26f6664221194d964cb Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 17:54:47 +0200 Subject: [PATCH 34/36] fix(datasetattributes, mapper): fix refactoring coherence in choices + fix to have exact same behavior --- Sources/Common/DataModel/DataSetAttributes/FieldData.js | 3 +-- Sources/Rendering/Core/Mapper/index.js | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Sources/Common/DataModel/DataSetAttributes/FieldData.js b/Sources/Common/DataModel/DataSetAttributes/FieldData.js index 4671c3b6231..4e4897acefc 100644 --- a/Sources/Common/DataModel/DataSetAttributes/FieldData.js +++ b/Sources/Common/DataModel/DataSetAttributes/FieldData.js @@ -197,14 +197,13 @@ export function extend(publicAPI, model, initialValues = {}) { macro.obj(publicAPI, model); - vtkFieldData(publicAPI, model); - // Decode serialized data if any if (initialValues.arrays) { initialValues.arrays = initialValues.arrays.map((item) => ({ data: vtk(item.data), })); } + vtkFieldData(publicAPI, model); } // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/Core/Mapper/index.js b/Sources/Rendering/Core/Mapper/index.js index 284b6f44f22..215abeb8288 100644 --- a/Sources/Rendering/Core/Mapper/index.js +++ b/Sources/Rendering/Core/Mapper/index.js @@ -600,7 +600,7 @@ function defaultValues(initialValues) { useInvertibleColors: false, invertibleScalars: null, - viewSpecificProperties: null, + viewSpecificProperties: {}, customShaderAttributes: [], ...initialValues, @@ -639,10 +639,6 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.setGetArray(publicAPI, model, ['scalarRange'], 2); - if (!initialValues.viewSpecificProperties) { - initialValues.viewSpecificProperties = {}; - } - CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model); // Object methods From 8fb9e8dcaabd05f80556de12988f0060850450f7 Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 18:39:24 +0200 Subject: [PATCH 35/36] fix(renderer,viewnode,renderwindow,...): fix refactoring coherence in choices --- Sources/Rendering/Core/Mapper2D/index.js | 6 +- Sources/Rendering/Core/Prop3D/index.js | 17 ++-- Sources/Rendering/Core/Property/index.js | 3 +- Sources/Rendering/Core/RenderWindow/index.js | 32 +++---- Sources/Rendering/Core/Renderer/index.js | 3 +- Sources/Rendering/Core/Viewport/index.js | 38 ++++---- .../OpenGL/HardwareSelector/index.js | 50 +++++----- .../Rendering/OpenGL/RenderWindow/index.js | 92 +++++++++---------- Sources/Rendering/OpenGL/ShaderCache/index.js | 5 +- Sources/Rendering/OpenGL/Texture/index.js | 2 +- .../Rendering/OpenGL/ViewNodeFactory/index.js | 9 +- .../Rendering/SceneGraph/RenderPass/index.js | 30 +++--- .../SceneGraph/RenderWindowViewNode/index.js | 6 +- .../SceneGraph/ViewNodeFactory/index.js | 22 ++--- Sources/Rendering/WebGPU/Actor/index.js | 43 +++++---- .../WebGPU/HardwareSelectionPass/index.js | 26 +++--- .../WebGPU/HardwareSelector/index.js | 24 ++--- .../Rendering/WebGPU/RenderWindow/index.js | 32 +++---- Sources/Rendering/WebGPU/ShaderCache/index.js | 7 +- .../Rendering/WebGPU/ViewNodeFactory/index.js | 9 +- 20 files changed, 218 insertions(+), 238 deletions(-) diff --git a/Sources/Rendering/Core/Mapper2D/index.js b/Sources/Rendering/Core/Mapper2D/index.js index 6c0a61a5356..897df3c5e07 100644 --- a/Sources/Rendering/Core/Mapper2D/index.js +++ b/Sources/Rendering/Core/Mapper2D/index.js @@ -166,7 +166,7 @@ function defaultValues(initialValues) { transformCoordinate: null, - viewSpecificProperties: null, + viewSpecificProperties: {}, customShaderAttributes: [], ...initialValues, }; @@ -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); } diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index 9454207da06..3c29d34654e 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -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); @@ -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(); }; @@ -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()) { diff --git a/Sources/Rendering/Core/Property/index.js b/Sources/Rendering/Core/Property/index.js index 3dfb4fdf6a6..197fecd7dae 100644 --- a/Sources/Rendering/Core/Property/index.js +++ b/Sources/Rendering/Core/Property/index.js @@ -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)) { diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index f5072862711..e974d8969fa 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -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 // ---------------------------------------------------------------------------- @@ -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 = {}) { diff --git a/Sources/Rendering/Core/Renderer/index.js b/Sources/Rendering/Core/Renderer/index.js index 1bb1ba08eda..7be064fc1a4 100644 --- a/Sources/Rendering/Core/Renderer/index.js +++ b/Sources/Rendering/Core/Renderer/index.js @@ -565,6 +565,8 @@ function vtkRenderer(publicAPI, model) { function defaultValues(initialValues) { return { + background: [0, 0, 0, 1], + pickedProp: null, activeCamera: null, @@ -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); diff --git a/Sources/Rendering/Core/Viewport/index.js b/Sources/Rendering/Core/Viewport/index.js index 253e5554979..238ac9c3f27 100644 --- a/Sources/Rendering/Core/Viewport/index.js +++ b/Sources/Rendering/Core/Viewport/index.js @@ -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 // ---------------------------------------------------------------------------- @@ -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 = {}) { diff --git a/Sources/Rendering/OpenGL/HardwareSelector/index.js b/Sources/Rendering/OpenGL/HardwareSelector/index.js index 5397657cff6..93ed4687e02 100644 --- a/Sources/Rendering/OpenGL/HardwareSelector/index.js +++ b/Sources/Rendering/OpenGL/HardwareSelector/index.js @@ -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 // ---------------------------------------------------------------------------- @@ -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]); @@ -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 = {}) { @@ -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', diff --git a/Sources/Rendering/OpenGL/RenderWindow/index.js b/Sources/Rendering/OpenGL/RenderWindow/index.js index fa7ea95fe57..ebdcb65794c 100644 --- a/Sources/Rendering/OpenGL/RenderWindow/index.js +++ b/Sources/Rendering/OpenGL/RenderWindow/index.js @@ -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 // ---------------------------------------------------------------------------- @@ -1249,6 +1220,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 = {}) { @@ -1257,35 +1263,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(); @@ -1322,6 +1317,9 @@ export function extend(publicAPI, model, initialValues = {}) { // Object methods vtkOpenGLRenderWindow(publicAPI, model); + + initialValues.selector.setOpenGLRenderWindow(publicAPI); + initialValues.shaderCache.setOpenGLRenderWindow(publicAPI); } // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ShaderCache/index.js b/Sources/Rendering/OpenGL/ShaderCache/index.js index 9f6720959dc..a4f41b3f752 100644 --- a/Sources/Rendering/OpenGL/ShaderCache/index.js +++ b/Sources/Rendering/OpenGL/ShaderCache/index.js @@ -236,6 +236,8 @@ function vtkShaderCache(publicAPI, model) { function defaultValues(initialValues) { return { + // Internal objects + shaderPrograms: {}, lastShaderBound: null, context: null, // _openGLRenderWindow: null, @@ -249,9 +251,6 @@ export function extend(publicAPI, model, initialValues = {}) { macro.moveToProtected(publicAPI, initialValues, ['openGLRenderWindow']); Object.assign(initialValues, defaultValues(initialValues)); - // Internal objects - initialValues.shaderPrograms = {}; - // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, SET_GET_FIELDS); diff --git a/Sources/Rendering/OpenGL/Texture/index.js b/Sources/Rendering/OpenGL/Texture/index.js index 30b8dc30a30..7c3dedb5e85 100644 --- a/Sources/Rendering/OpenGL/Texture/index.js +++ b/Sources/Rendering/OpenGL/Texture/index.js @@ -1531,7 +1531,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLTexture'); +export const newInstance = macro.newInstance(extend, 'vtkOpenGLTexture', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js index ccdf5c46394..11141a20765 100644 --- a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js +++ b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js @@ -21,7 +21,11 @@ function vtkOpenGLViewNodeFactory(publicAPI, model) { // ---------------------------------------------------------------------------- function defaultValues(initialValues) { - return { ...initialValues }; + return { + // Static class mapping shared across instances + overrides: CLASS_MAPPING, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -29,9 +33,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - // Static class mapping shared across instances - initialValues.overrides = CLASS_MAPPING; - // Inheritance vtkViewNodeFactory.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/SceneGraph/RenderPass/index.js b/Sources/Rendering/SceneGraph/RenderPass/index.js index 303e8f3bb75..6eae0809daf 100644 --- a/Sources/Rendering/SceneGraph/RenderPass/index.js +++ b/Sources/Rendering/SceneGraph/RenderPass/index.js @@ -1,20 +1,5 @@ import macro from 'vtk.js/Sources/macros'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - delegates: [], - currentOperation: null, - preDelegateOperations: [], - postDelegateOperations: [], - currentParent: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- function vtkRenderPass(publicAPI, model) { @@ -62,6 +47,21 @@ function vtkRenderPass(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + delegates: [], + currentOperation: null, + preDelegateOperations: [], + postDelegateOperations: [], + currentParent: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index b3d5c45a2ea..52e96586aee 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -152,6 +152,7 @@ function vtkRenderWindowViewNode(publicAPI, model) { function defaultValues(initialValues) { return { + size: [300, 300], selector: undefined, ...initialValues, }; @@ -161,11 +162,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - - if (!initialValues.size) { - initialValues.size = [300, 300]; - } - macro.getArray(publicAPI, model, ['size'], 2); macro.get(publicAPI, model, ['selector']); diff --git a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js index dc703ecca80..f4a222b51b9 100644 --- a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js +++ b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js @@ -1,16 +1,5 @@ import macro from 'vtk.js/Sources/macros'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - // overrides: {}, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkViewNodeFactory methods // ---------------------------------------------------------------------------- @@ -54,6 +43,17 @@ function vtkViewNodeFactory(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // overrides: {}, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/Actor/index.js b/Sources/Rendering/WebGPU/Actor/index.js index be47e4b7011..3b185b8cca0 100644 --- a/Sources/Rendering/WebGPU/Actor/index.js +++ b/Sources/Rendering/WebGPU/Actor/index.js @@ -5,18 +5,6 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; import { registerOverride } from 'vtk.js/Sources/Rendering/WebGPU/ViewNodeFactory'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - propID: undefined, - bufferShift: undefined, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkWebGPUActor methods // ---------------------------------------------------------------------------- @@ -160,6 +148,27 @@ function vtkWebGPUActor(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal objects + keyMatricesTime: macro.obj({}, { mtime: 0 }), + keyMatrices: { + normalMatrix: new Float64Array(16), + bcwc: new Float64Array(16), + bcsc: new Float64Array(16), + }, + bufferShift: [0, 0, 0, 0], + + propID: undefined, + bufferShift: undefined, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -168,18 +177,8 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - initialValues.keyMatricesTime = {}; - macro.obj(initialValues.keyMatricesTime, { mtime: 0 }); - initialValues.keyMatrices = { - normalMatrix: new Float64Array(16), - bcwc: new Float64Array(16), - bcsc: new Float64Array(16), - }; - macro.get(publicAPI, model, ['propID', 'keyMatricesTime']); - initialValues.bufferShift = [0, 0, 0, 0]; - // Object methods vtkWebGPUActor(publicAPI, model); } diff --git a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js index 5577dc79518..5b1d81f1577 100644 --- a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js @@ -4,19 +4,6 @@ import vtkWebGPUTexture from 'vtk.js/Sources/Rendering/WebGPU/Texture'; import vtkWebGPUShaderCache from 'vtk.js/Sources/Rendering/WebGPU/ShaderCache'; import vtkRenderPass from 'vtk.js/Sources/Rendering/SceneGraph/RenderPass'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - selectionRenderEncoder: null, - colorTexture: null, - depthTexture: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- function vtkWebGPUHardwareSelectionPass(publicAPI, model) { @@ -129,6 +116,19 @@ function vtkWebGPUHardwareSelectionPass(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + selectionRenderEncoder: null, + colorTexture: null, + depthTexture: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/HardwareSelector/index.js b/Sources/Rendering/WebGPU/HardwareSelector/index.js index c73830208f3..aa32b14e7c3 100644 --- a/Sources/Rendering/WebGPU/HardwareSelector/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelector/index.js @@ -252,18 +252,6 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { return convertSelection(buffdata.fieldAssociation, dataMap, buffdata); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - WebGPURenderWindow: null, - _selectionPass: vtkWebGPUHardwareSelectionPass.newInstance(), - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkWebGPUHardwareSelector methods // ---------------------------------------------------------------------------- @@ -425,6 +413,18 @@ function vtkWebGPUHardwareSelector(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + WebGPURenderWindow: null, + _selectionPass: vtkWebGPUHardwareSelectionPass.newInstance(), + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/RenderWindow/index.js b/Sources/Rendering/WebGPU/RenderWindow/index.js index ca0252aaf44..6c50df58ced 100644 --- a/Sources/Rendering/WebGPU/RenderWindow/index.js +++ b/Sources/Rendering/WebGPU/RenderWindow/index.js @@ -550,6 +550,11 @@ function vtkWebGPURenderWindow(publicAPI, model) { function defaultValues(initialValues) { return { + // Internal instances + bgImage: new Image(), + myFactory: vtkWebGPUViewNodeFactory.newInstance(), + selector: vtkWebGPUHardwareSelector.newInstance(), + initialized: false, context: null, adapter: null, @@ -574,35 +579,28 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(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%'; - // Create internal bgImage - model.bgImage = new Image(); - delete initialValues.bgImage; - 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'; + 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'; // Inheritance vtkRenderWindowViewNode.extend(publicAPI, model, initialValues); - model.myFactory = vtkWebGPUViewNodeFactory.newInstance(); /* eslint-disable no-use-before-define */ - model.myFactory.registerOverride('vtkRenderWindow', newInstance); + initialValues.myFactory.registerOverride('vtkRenderWindow', newInstance); /* eslint-enable no-use-before-define */ // setup default forward pass rendering - model.renderPasses[0] = vtkForwardPass.newInstance(); + initialValues.renderPasses[0] = vtkForwardPass.newInstance(); - if (!initialValues.selector) { - initialValues.selector = vtkWebGPUHardwareSelector.newInstance(); - initialValues.selector.setWebGPURenderWindow(publicAPI); - } + initialValues.selector.setWebGPURenderWindow(publicAPI); macro.event(publicAPI, model, 'imageReady'); macro.event(publicAPI, model, 'initialized'); diff --git a/Sources/Rendering/WebGPU/ShaderCache/index.js b/Sources/Rendering/WebGPU/ShaderCache/index.js index 6a21632ec2c..85d1d9a19aa 100644 --- a/Sources/Rendering/WebGPU/ShaderCache/index.js +++ b/Sources/Rendering/WebGPU/ShaderCache/index.js @@ -54,7 +54,7 @@ function vtkWebGPUShaderCache(publicAPI, model) { function defaultValues(initialValues) { return { - shaderModules: null, + _shaderModules: new Map(), device: null, window: null, ...initialValues, @@ -64,11 +64,8 @@ function defaultValues(initialValues) { // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { + macro.moveToProtected(publicAPI, initialValues, ['shaderModules']); Object.assign(initialValues, defaultValues(initialValues)); - - // Internal objects - model._shaderModules = new Map(); - // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['device', 'window']); diff --git a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js index 1bf7c86784d..829fd28dee2 100644 --- a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js +++ b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js @@ -21,7 +21,11 @@ function vtkWebGPUViewNodeFactory(publicAPI, model) { // ---------------------------------------------------------------------------- function defaultValues(initialValues) { - return { ...initialValues }; + return { + // Static class mapping shared across instances + overrides: CLASS_MAPPING, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -29,9 +33,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - // Static class mapping shared across instances - model.overrides = CLASS_MAPPING; - // Inheritance vtkViewNodeFactory.extend(publicAPI, model, initialValues); From 7f15397b5ae33352d06ea4e0a730a2ad1d0ea49f Mon Sep 17 00:00:00 2001 From: joannacirillo Date: Wed, 15 Jun 2022 18:40:01 +0200 Subject: [PATCH 36/36] refactor(remoteview): refactor constructor refactor constructor to call setters at instanciation --- Sources/Rendering/Misc/RemoteView/index.js | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Sources/Rendering/Misc/RemoteView/index.js b/Sources/Rendering/Misc/RemoteView/index.js index 1845ee1b189..42db0be0c6c 100644 --- a/Sources/Rendering/Misc/RemoteView/index.js +++ b/Sources/Rendering/Misc/RemoteView/index.js @@ -187,21 +187,24 @@ function vtkRemoteView(publicAPI, model) { // Object factory // ---------------------------------------------------------------------------- -const DEFAULT_VALUES = { - viewId: '-1', - interactiveQuality: 60, - interactiveRatio: 1 / window.devicePixelRatio, - stillQuality: 100, - stillRatio: 1, - rpcMouseEvent: 'viewport.mouse.interaction', - rpcGestureEvent: null, - rpcWheelEvent: null, -}; +function defaultValues(initialValues) { + return { + viewId: '-1', + interactiveQuality: 60, + interactiveRatio: 1 / window.devicePixelRatio, + stillQuality: 100, + stillRatio: 1, + rpcMouseEvent: 'viewport.mouse.interaction', + rpcGestureEvent: null, + rpcWheelEvent: null, + ...initialValues, + }; +} // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { - Object.assign(model, DEFAULT_VALUES, initialValues); + Object.assign(initialValues, defaultValues(initialValues)); macro.obj(publicAPI, model, initialValues); macro.get(publicAPI, model, [