Skip to content

Commit 7845f6a

Browse files
authored
Merge pull request #2532 from DavidBerger98/vtkClipClosedSurface
Add vtkClipClosedSurface
2 parents b771c7d + 9a9be4a commit 7845f6a

File tree

40 files changed

+6776
-100
lines changed

40 files changed

+6776
-100
lines changed

Sources/Common/Core/CellArray/index.d.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { TypedArray } from "../../../types";
2-
import vtkDataArray from "../../Core/DataArray";
2+
import vtkDataArray, { IDataArrayInitialValues } from "../../Core/DataArray";
33

44

55
/**
6-
*
6+
* The inital values of a vtkCellArray.
77
*/
8-
export interface ICellArrayInitialValues {
8+
export interface ICellArrayInitialValues extends IDataArrayInitialValues {
99
empty?: boolean;
10-
numberOfComponents?: number;
1110
}
1211

1312
export interface vtkCellArray extends vtkDataArray {
@@ -19,22 +18,35 @@ export interface vtkCellArray extends vtkDataArray {
1918
getNumberOfCells(recompute?: boolean): number;
2019

2120
/**
22-
*
21+
* Get the sizes of the cells in this array.
2322
* @param {Boolean} [recompute] Recompute the cell sizes.
2423
*/
2524
getCellSizes(recompute?: boolean): any;
2625

2726
/**
28-
*
29-
* @param {TypedArray} typedArray The typedArray value.
27+
* Set the data of this array.
28+
* @param {TypedArray} typedArray The Array value.
3029
*/
3130
setData(typedArray: TypedArray): void;
3231

3332
/**
34-
* Returns the point indexes at the given location as a subarray.
33+
* Returns the point indices at the given location as a subarray.
3534
* @param loc
3635
*/
3736
getCell(loc: any): void;
37+
38+
/**
39+
* Reset the cell array by setting the number of cells to 0.
40+
* NOTE: This won't touch the actual memory of the underlying typedArray.
41+
*/
42+
initialize(): void;
43+
44+
/**
45+
* Insert a cell to this array in the next available slot.
46+
* @param {Number[]} cellPointIds The list of point ids (NOT prefixed with the number of points)
47+
* @returns {Number} Idx of where the cell was inserted
48+
*/
49+
insertNextCell(cellPointIds: number[]): number;
3850
}
3951

4052
/**

Sources/Common/Core/CellArray/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function vtkCellArray(publicAPI, model) {
5151
if (model.cellSizes) {
5252
model.numberOfCells = model.cellSizes.length;
5353
} else {
54-
model.numberOfCells = getNumberOfCells(model.values);
54+
model.numberOfCells = getNumberOfCells(publicAPI.getData());
5555
}
5656
return model.numberOfCells;
5757
};
@@ -61,7 +61,7 @@ function vtkCellArray(publicAPI, model) {
6161
return model.cellSizes;
6262
}
6363

64-
model.cellSizes = extractCellSizes(model.values);
64+
model.cellSizes = extractCellSizes(publicAPI.getData());
6565
return model.cellSizes;
6666
};
6767

@@ -72,14 +72,30 @@ function vtkCellArray(publicAPI, model) {
7272
model.cellSizes = undefined;
7373
};
7474

75-
/**
76-
* Returns the point indexes at the given location as a subarray.
77-
*/
7875
publicAPI.getCell = (loc) => {
7976
let cellLoc = loc;
8077
const numberOfPoints = model.values[cellLoc++];
8178
return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
8279
};
80+
81+
const superInitialize = publicAPI.initialize;
82+
publicAPI.initialize = () => {
83+
superInitialize();
84+
// Set to undefined to ensure insertNextCell works correctly
85+
model.numberOfCells = undefined;
86+
model.cellSizes = undefined;
87+
};
88+
89+
publicAPI.insertNextCell = (cellPointIds) => {
90+
const cellId = publicAPI.getNumberOfCells();
91+
publicAPI.insertNextTuples([cellPointIds.length, ...cellPointIds]);
92+
// By computing the number of cells earlier, we made sure that numberOfCells is defined
93+
++model.numberOfCells;
94+
if (model.cellSizes != null) {
95+
model.cellSizes.push(cellPointIds.length);
96+
}
97+
return cellId;
98+
};
8399
}
84100

85101
// ----------------------------------------------------------------------------

Sources/Common/Core/CellArray/test/testCellArray.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,34 @@ test('Test cell array constructor', (t) => {
3434

3535
t.end();
3636
});
37+
38+
test('Test vtkCellArray insertNextCell', (t) => {
39+
const cellArray = vtkCellArray.newInstance({
40+
dataType: 'Uint16Array',
41+
empty: true,
42+
numberOfComponents: 1,
43+
});
44+
cellArray.insertNextCell([0, 1, 2]);
45+
t.equal(
46+
cellArray.getNumberOfCells(),
47+
1,
48+
'number of cells after first insertNextCell'
49+
);
50+
t.deepEqual(
51+
cellArray.getData(),
52+
Uint16Array.from([3, 0, 1, 2]),
53+
'getData after first insertNextCell'
54+
);
55+
cellArray.insertNextCell([3, 4, 5, 6]);
56+
t.equal(
57+
cellArray.getNumberOfCells(),
58+
2,
59+
'number of cells after second insertNextCell'
60+
);
61+
t.deepEqual(
62+
cellArray.getData(),
63+
Uint16Array.from([3, 0, 1, 2, 4, 3, 4, 5, 6]),
64+
'getData after second insertNextCell'
65+
);
66+
t.end();
67+
});

0 commit comments

Comments
 (0)