Skip to content

Commit c6be4b0

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 71fa4cd commit c6be4b0

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

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

Lines changed: 4 additions & 4 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.
@@ -39,10 +39,10 @@ export interface vtkAbstractMapper extends vtkAbstractMapperBase {
3939
removeAllClippingPlanes(): void;
4040

4141
/**
42-
* Remove clipping plane at index i.
43-
* @param {Number} i
42+
* Remove clipping plane.
43+
* @param {vtkPlane} plane
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +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-
model.clippingPlanes.push(plane);
17-
publicAPI.modified();
17+
if (!model.clippingPlanes.includes(plane)) {
18+
model.clippingPlanes.push(plane);
19+
publicAPI.modified();
20+
return true;
21+
}
22+
return false;
1823
};
1924

2025
publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length;
@@ -23,11 +28,14 @@ function vtkAbstractMapper(publicAPI, model) {
2328
model.clippingPlanes.length = 0;
2429
};
2530

26-
publicAPI.removeClippingPlane = (i) => {
27-
if (i < 0 || i >= 6) {
28-
return;
31+
publicAPI.removeClippingPlane = (clippingPlane) => {
32+
const i = model.clippingPlanes.indexOf(clippingPlane);
33+
if (i === -1) {
34+
return false;
2935
}
3036
model.clippingPlanes.splice(i, 1);
37+
publicAPI.modified();
38+
return true;
3139
};
3240

3341
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)