Skip to content

Commit 2306726

Browse files
fix(AbstractMapper): Add missing class hierarchy
Added missing class hierarchy for AbstractMapper. Removed extra extend calls from VolumeMapper. BREAKING CHANGE: Changed removeClippingPlane to use instance instead of index.
1 parent 2ea94a2 commit 2306726

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

Sources/Rendering/Core/AbstractMapper/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface vtkAbstractMapper extends vtkAbstractMapperBase {
1919
* Added plane needs to be a vtkPlane object.
2020
* @param {vtkPlane} plane
2121
*/
22-
addClippingPlane(plane: vtkPlane): void;
22+
addClippingPlane(plane: vtkPlane): boolean;
2323

2424
/**
2525
* Get number of clipping planes.
@@ -42,7 +42,7 @@ export interface vtkAbstractMapper extends vtkAbstractMapperBase {
4242
* Remove clipping plane at index i.
4343
* @param {Number} i
4444
*/
45-
removeClippingPlane(i: number): void;
45+
removeClippingPlane(plane: vtkPlane): boolean;
4646

4747
/**
4848
* Set clipping planes.

Sources/Rendering/Core/AbstractMapper/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ import macro from 'vtk.js/Sources/macros';
55
// ----------------------------------------------------------------------------
66

77
function vtkAbstractMapper(publicAPI, model) {
8+
model.classHierarchy.push('vtkAbstractMapper');
89
publicAPI.update = () => {
910
publicAPI.getInputData();
1011
};
1112

1213
publicAPI.addClippingPlane = (plane) => {
13-
if (plane.getClassName() !== 'vtkPlane') {
14-
return;
14+
if (!plane.isA('vtkPlane')) {
15+
return false;
16+
}
17+
if (!model.clippingPlanes.includes(plane)) {
18+
model.clippingPlanes.push(plane);
19+
publicAPI.modified();
20+
return true;
1521
}
16-
model.clippingPlanes.push(plane);
22+
return false;
1723
};
1824

1925
publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length;
@@ -22,11 +28,14 @@ function vtkAbstractMapper(publicAPI, model) {
2228
model.clippingPlanes.length = 0;
2329
};
2430

25-
publicAPI.removeClippingPlane = (i) => {
26-
if (i < 0 || i >= 6) {
27-
return;
31+
publicAPI.removeClippingPlane = (clippingPlane) => {
32+
const i = model.clippingPlanes.indexOf(clippingPlane);
33+
if (i === -1) {
34+
return false;
2835
}
2936
model.clippingPlanes.splice(i, 1);
37+
publicAPI.modified();
38+
return true;
3039
};
3140

3241
publicAPI.getClippingPlanes = () => model.clippingPlanes;

Sources/Rendering/Core/AbstractMapper/test/testAbstractMapper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ test('Test vtkAbstractMapper publicAPI', (t) => {
1616
const plane = vtkPlane.newInstance({ normal: normals[0] });
1717
mapper.addClippingPlane(plane);
1818
t.equal(mapper.getClippingPlanes().length, 1);
19-
mapper.removeClippingPlane(0);
19+
mapper.removeClippingPlane(plane);
2020
t.equal(mapper.getClippingPlanes().length, 0);
2121
mapper.setClippingPlanes(plane);
2222
t.equal(mapper.getClippingPlanes().length, 1);
2323
mapper.removeAllClippingPlanes();
2424
t.equal(mapper.getClippingPlanes().length, 0);
25-
mapper.removeClippingPlane(0);
25+
mapper.removeClippingPlane(plane);
2626

2727
const plane2 = vtkPlane.newInstance({ normal: normals[1] });
2828
const plane3 = vtkPlane.newInstance({ normal: normals[2] });
2929

3030
mapper.setClippingPlanes([plane, plane2, plane3]);
3131
t.equal(mapper.getClippingPlanes().length, 3);
32-
mapper.removeClippingPlane(0);
32+
mapper.removeClippingPlane(plane);
3333
t.equal(mapper.getClippingPlanes().length, 2);
3434
for (let i = 0; i < mapper.getClippingPlanes().length; i++) {
3535
const normal = mapper.getClippingPlanes()[i].getNormal();

Sources/Rendering/Core/VolumeMapper/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ export function extend(publicAPI, model, initialValues = {}) {
9898

9999
vtkAbstractMapper.extend(publicAPI, model, initialValues);
100100

101-
// Build VTK API
102-
macro.obj(publicAPI, model);
103-
macro.algo(publicAPI, model, 1, 0);
104-
105101
macro.setGet(publicAPI, model, [
106102
'sampleDistance',
107103
'imageSampleDistance',

0 commit comments

Comments
 (0)