Skip to content

Commit 123dfac

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 39158c3 commit 123dfac

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +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;
1516
}
16-
for (let i = 0; i < model.clippingPlanes.length; i++) {
17-
if (model.clippingPlanes[i] === plane) return;
17+
if (!model.clippingPlanes.includes(plane)) {
18+
model.clippingPlanes.push(plane);
19+
publicAPI.modified();
20+
return true;
1821
}
19-
model.clippingPlanes.push(plane);
22+
return false;
2023
};
2124

2225
publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length;
@@ -25,11 +28,14 @@ function vtkAbstractMapper(publicAPI, model) {
2528
model.clippingPlanes.length = 0;
2629
};
2730

28-
publicAPI.removeClippingPlane = (i) => {
29-
if (i < 0 || i >= 6) {
30-
return;
31+
publicAPI.removeClippingPlane = (clippingPlane) => {
32+
const i = model.clippingPlanes.indexOf(clippingPlane);
33+
if (i === -1) {
34+
return false;
3135
}
3236
model.clippingPlanes.splice(i, 1);
37+
publicAPI.modified();
38+
return true;
3339
};
3440

3541
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
@@ -99,10 +99,6 @@ export function extend(publicAPI, model, initialValues = {}) {
9999

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

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

0 commit comments

Comments
 (0)