-
-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathindex.js
More file actions
115 lines (94 loc) · 3.38 KB
/
index.js
File metadata and controls
115 lines (94 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import macro from 'vtk.js/Sources/macros';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants';
// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------
function extractCellSizes(cellArray) {
let currentIdx = 0;
return cellArray.filter((value, index) => {
if (index === currentIdx) {
currentIdx += value + 1;
return true;
}
return false;
});
}
function getNumberOfCells(cellArray) {
if (!cellArray) return 0;
let cellId = 0;
for (let cellArrayIndex = 0; cellArrayIndex < cellArray.length; ) {
cellArrayIndex += cellArray[cellArrayIndex] + 1;
cellId++;
}
return cellId;
}
// ----------------------------------------------------------------------------
// Static API
// ----------------------------------------------------------------------------
export const STATIC = {
extractCellSizes,
getNumberOfCells,
};
// ----------------------------------------------------------------------------
// vtkCellArray methods
// ----------------------------------------------------------------------------
function vtkCellArray(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkCellArray');
publicAPI.getNumberOfCells = (recompute) => {
if (model.numberOfCells !== undefined && !recompute) {
return model.numberOfCells;
}
if (model.cellSizes) {
model.numberOfCells = model.cellSizes.length;
} else {
model.numberOfCells = getNumberOfCells(model.values);
}
return model.numberOfCells;
};
publicAPI.getCellSizes = (recompute) => {
if (model.cellSizes !== undefined && !recompute) {
return model.cellSizes;
}
model.cellSizes = extractCellSizes(model.values);
return model.cellSizes;
};
const superSetData = publicAPI.setData;
publicAPI.setData = (typedArray) => {
superSetData(typedArray, 1);
model.numberOfCells = undefined;
model.cellSizes = undefined;
};
/**
* Returns the point indexes at the given location as a subarray.
*/
publicAPI.getCell = (loc) => {
let cellLoc = loc;
const numberOfPoints = model.values[cellLoc++];
return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
};
}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
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,
...initialValues,
};
}
// ----------------------------------------------------------------------------
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(initialValues, defaultValues(initialValues));
vtkDataArray.extend(publicAPI, model, initialValues);
vtkCellArray(publicAPI, model);
}
// ----------------------------------------------------------------------------
export const newInstance = macro.newInstance(extend, 'vtkCellArray', true);
// ----------------------------------------------------------------------------
export default { newInstance, extend, ...STATIC };