Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor constructors #2409

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5aeba62
refactor(fullscreenrenderwindow, dataarray, remoteview, macro): refac…
joannacirillo Apr 28, 2022
4f77c69
feat(testmacro): defaultValues have protected values named with under…
joannacirillo May 31, 2022
a89d4da
fix(hardwareselector, renderwindow): fix after refactor
joannacirillo Jun 3, 2022
ff88fd8
fix(actor2d): change constructor to call setters
joannacirillo Jun 8, 2022
787a134
fix(abstractmapper): fix setClippingPlane at instanciation
joannacirillo Jun 8, 2022
592e0e0
fix(actor,actor2d): fix refactoring
joannacirillo Jun 8, 2022
f011c14
fix(hardwareselector, renderwindow): fix refactoring
joannacirillo Jun 9, 2022
b2d09ed
fix(polydatamapper2d): refactor constructor
joannacirillo Jun 9, 2022
27e181b
fix(datasetattributes): refactor constructors
joannacirillo Jun 10, 2022
c1f6ef6
fix(colortransferfunction): refactor constructor to call setters
joannacirillo Jun 13, 2022
b70c1c9
refactor(fielddata): improvement of getArrayWithIndexFix
joannacirillo Jun 13, 2022
ea47367
refactor(polydatamapper): put some values in default rather than set …
joannacirillo Jun 13, 2022
986dfc1
fix(renderwindow): fix
joannacirillo Jun 14, 2022
0672218
fix(abstractmapper): remove useless initialValues setting
joannacirillo Jun 14, 2022
62ca1dd
refactor(filtersources): refactor constructors to call setters
joannacirillo Jun 14, 2022
763e1cf
fix(renderwindow): fix after refactor
joannacirillo Jun 14, 2022
d607ff7
refactor(tmp): temporary to only call setters for modified files
joannacirillo Jun 14, 2022
ea30a90
fix(polydatamapper): fix refactoring
joannacirillo Jun 15, 2022
141eb1f
refactor(helper): refactor constructor to call setters
joannacirillo Jun 15, 2022
531eb9a
fix(testactor2d): remove .only(
joannacirillo Jun 15, 2022
01407f9
refactor(volume, texture): refactor constructor to call setters
joannacirillo Jun 15, 2022
12c88ab
refactor(sources): refactoring constructors
joannacirillo Jun 15, 2022
1bb1060
test(points): add some tests for points
joannacirillo Jun 15, 2022
9b571db
refactor(stringarray,variantarray,progresshandler,priorityqueue): ref…
joannacirillo Jun 15, 2022
afb7f86
fix(lookuptable): fix refactoring
joannacirillo Jun 15, 2022
562a185
refactor(cell): refactor constructor to call setters
joannacirillo Jun 15, 2022
d2725c2
docs(lookuptable, appendpolydata): document some implementation choices
joannacirillo Jun 15, 2022
7824f27
fix(lookuptable): fix previous commit
joannacirillo Jun 15, 2022
b14ebe2
fix(abstractmapper, selectionnode): fix refactoring
joannacirillo Jun 15, 2022
ad468f2
refactor(triangle, line): refactor constructors
joannacirillo Jun 15, 2022
b74186e
fix(camera): fix refactoring
joannacirillo Jun 15, 2022
d4def46
fix(camera): fix previous commit
joannacirillo Jun 15, 2022
df6db6f
fix(coordinate, hardwareselector): fix refactoring
joannacirillo Jun 15, 2022
114330e
fix(datasetattributes, mapper): fix refactoring
joannacirillo Jun 15, 2022
8fb9e8d
fix(renderer,viewnode,renderwindow,...): fix refactoring
joannacirillo Jun 15, 2022
7f15397
refactor(remoteview): refactor constructor
joannacirillo Jun 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/Common/Core/CellArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -98,13 +101,14 @@ 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);
}

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

export const newInstance = macro.newInstance(extend, 'vtkCellArray');
export const newInstance = macro.newInstance(extend, 'vtkCellArray', true);

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

Expand Down
4 changes: 3 additions & 1 deletion Sources/Common/Core/DataArray/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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;

Expand Down
83 changes: 54 additions & 29 deletions Sources/Common/Core/DataArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand All @@ -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;
}
Expand Down Expand Up @@ -313,49 +319,68 @@ 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) {
finetjul marked this conversation as resolved.
Show resolved Hide resolved
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);
finetjul marked this conversation as resolved.
Show resolved Hide resolved
finetjul marked this conversation as resolved.
Show resolved Hide resolved
joannacirillo marked this conversation as resolved.
Show resolved Hide resolved
joannacirillo marked this conversation as resolved.
Show resolved Hide resolved
delete initialValues.values;
delete initialValues.dataType;
delete initialValues.numberOfComponents;
delete initialValues.size;
}

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

export const newInstance = macro.newInstance(extend, 'vtkDataArray');
export const newInstance = macro.newInstance(extend, 'vtkDataArray', true);

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

Expand Down
Loading