Skip to content

Commit 18ce605

Browse files
authored
Merge pull request #43 from FezVrasta/perf/georep-cubeaxes
perf: properly disable CubeAxes on GeometryRepresentation
2 parents b1dc18c + 36f7adf commit 18ce605

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

src/core/GeometryRepresentation.js

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ export default class GeometryRepresentation extends Component {
3838
});
3939
this.actor.setMapper(this.mapper);
4040

41-
// Cube Axes
41+
// Scalar Bar
42+
this.scalarBar = vtkScalarBarActor.newInstance();
43+
this.scalarBar.setScalarsToColors(this.lookupTable);
44+
this.scalarBar.setVisibility(false);
45+
46+
this.subscriptions = [];
47+
48+
if (props.showCubeAxes) {
49+
this.initCubeAxes();
50+
}
51+
}
52+
53+
initCubeAxes = () => {
4254
this.cubeAxes = vtkCubeAxesActor.newInstance({
4355
visibility: false,
4456
dataBounds: [-1, 1, -1, 1, -1, 1],
@@ -47,11 +59,6 @@ export default class GeometryRepresentation extends Component {
4759
.getActors()
4860
.forEach(({ setVisibility }) => setVisibility(false));
4961

50-
// Scalar Bar
51-
this.scalarBar = vtkScalarBarActor.newInstance();
52-
this.scalarBar.setScalarsToColors(this.lookupTable);
53-
this.scalarBar.setVisibility(false);
54-
5562
const updateCubeAxes = () => {
5663
if (this.mapper.getInputData()) {
5764
if (this.subscriptions.length === 1) {
@@ -63,26 +70,30 @@ export default class GeometryRepresentation extends Component {
6370

6471
const bounds = this.mapper.getInputData().getBounds();
6572
if (bounds[0] < bounds[1]) {
66-
this.cubeAxes.setDataBounds(bounds);
73+
if (this.cubeAxes) {
74+
this.cubeAxes.setDataBounds(bounds);
75+
}
6776
if (this.view) {
6877
this.view.renderView();
6978
}
7079
}
7180
}
7281
};
7382

74-
this.subscriptions = [];
7583
this.subscriptions.push(this.mapper.onModified(updateCubeAxes));
76-
}
84+
};
7785

7886
render() {
7987
return (
8088
<ViewContext.Consumer>
8189
{(view) => {
8290
if (!this.view) {
83-
this.cubeAxes.setCamera(view.renderer.getActiveCamera());
91+
if (this.cubeAxes) {
92+
this.cubeAxes.setCamera(view.renderer.getActiveCamera());
93+
view.renderer.addActor(this.cubeAxes);
94+
}
95+
8496
view.renderer.addActor(this.scalarBar);
85-
view.renderer.addActor(this.cubeAxes);
8697
view.renderer.addActor(this.actor);
8798
this.view = view;
8899
}
@@ -122,8 +133,10 @@ export default class GeometryRepresentation extends Component {
122133
this.scalarBar.delete();
123134
this.scalarBar = null;
124135

125-
this.cubeAxes.delete();
126-
this.cubeAxes = null;
136+
if (this.cubeAxes) {
137+
this.cubeAxes.delete();
138+
this.cubeAxes = null;
139+
}
127140

128141
this.actor.delete();
129142
this.actor = null;
@@ -173,14 +186,21 @@ export default class GeometryRepresentation extends Component {
173186
this.lookupTable.updateRange();
174187
}
175188

176-
if (
177-
cubeAxesStyle &&
178-
(!previous || cubeAxesStyle !== previous.cubeAxesStyle)
179-
) {
180-
this.cubeAxes.set(cubeAxesStyle);
189+
if (showCubeAxes && this.cubeAxes == null) {
190+
this.initCubeAxes();
191+
192+
if (
193+
cubeAxesStyle &&
194+
(!previous || cubeAxesStyle !== previous.cubeAxesStyle)
195+
) {
196+
this.cubeAxes.set(cubeAxesStyle);
197+
}
181198
}
182199

183-
if (showCubeAxes !== this.cubeAxes.getVisibility()) {
200+
if (
201+
this.cubeAxes != null &&
202+
showCubeAxes !== this.cubeAxes.getVisibility()
203+
) {
184204
this.cubeAxes.setVisibility(showCubeAxes && this.validData);
185205
this.cubeAxes
186206
.getActors()
@@ -209,11 +229,14 @@ export default class GeometryRepresentation extends Component {
209229
this.validData = true;
210230
this.actor.setVisibility(this.currentVisibility);
211231
this.scalarBar.setVisibility(this.props.showScalarBar);
212-
this.cubeAxes.setVisibility(this.props.showCubeAxes);
213-
this.cubeAxes
214-
.getActors()
215-
.forEach(({ setVisibility }) => setVisibility(this.props.showCubeAxes));
216-
232+
if (this.cubeAxes) {
233+
this.cubeAxes.setVisibility(this.props.showCubeAxes);
234+
this.cubeAxes
235+
.getActors()
236+
.forEach(({ setVisibility }) =>
237+
setVisibility(this.props.showCubeAxes)
238+
);
239+
}
217240
// trigger render
218241
this.dataChanged();
219242
}

0 commit comments

Comments
 (0)