Skip to content

Commit e840d27

Browse files
authored
fix: Add requestAnimationFrame for Crosshairs SVG updates. Include la… (OHIF#36)
* fix: Add requestAnimationFrame for Crosshairs SVG updates. Include larger head model for testing performance * Fix lockfile
1 parent 9be5a56 commit e840d27

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed

examples/VTKCrosshairsExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class VTKCrosshairsExample extends Component {
7171

7272
volumeActor.setMapper(volumeMapper);
7373

74-
reader.setUrl('/headsq.vti', { loadData: true }).then(() => {
74+
reader.setUrl('/vmhead2-large.vti', { loadData: true }).then(() => {
7575
const data = reader.getOutputData();
7676
volumeMapper.setInputData(data);
7777

Binary file not shown.

public/vmhead2-large.vti/index.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"origin": [
3+
0.0,
4+
0.0,
5+
0.0
6+
],
7+
"cellData": {
8+
"arrays": [],
9+
"vtkClass": "vtkDataSetAttributes"
10+
},
11+
"FieldData": {
12+
"arrays": [],
13+
"vtkClass": "vtkDataSetAttributes"
14+
},
15+
"vtkClass": "vtkImageData",
16+
"pointData": {
17+
"arrays": [
18+
{
19+
"data": {
20+
"numberOfComponents": 1,
21+
"name": "nrrd75611",
22+
"vtkClass": "vtkDataArray",
23+
"dataType": "Uint16Array",
24+
"ranges": [
25+
{
26+
"max": 4095.0,
27+
"component": null,
28+
"min": 0.0
29+
}
30+
],
31+
"ref": {
32+
"encode": "LittleEndian",
33+
"basepath": "data",
34+
"id": "cd5fdd0a0c562d5753de2e8189c7fdf7",
35+
"registration": "setScalars"
36+
},
37+
"size": 77070336
38+
}
39+
}
40+
],
41+
"vtkClass": "vtkDataSetAttributes"
42+
},
43+
"spacing": [
44+
0.527344,
45+
0.527344,
46+
1.0
47+
],
48+
"extent": [
49+
0,
50+
511,
51+
0,
52+
511,
53+
0,
54+
293
55+
],
56+
"metadata": {
57+
"name": "vmhead2-large.vti"
58+
}
59+
}

src/VTKViewport/vtkSVGWidgetManager.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@ function vtkSVGWidgetManager(publicAPI, model) {
7474

7575
publicAPI.render = () => {
7676
if (model.svgRootNode) {
77-
const { scale } = model;
78-
const [width, height] = publicAPI.getSize();
79-
model.svgRootNode.setAttribute(
80-
'viewBox',
81-
`0 0 ${width * scale} ${height * scale}`
82-
);
83-
model.svgRootNode.setAttribute('width', `${width * scale}`);
84-
model.svgRootNode.setAttribute('height', `${height * scale}`);
85-
for (let i = 0; i < model.widgets.length; i++) {
86-
model.widgets[i].render(model.svgRootNode, model.scale);
87-
}
77+
// TODO: Not sure this is the best approach but it seems to be
78+
// making things smoother. Updating the DOM seemed to be
79+
// the performance bottleneck for the crosshairs tool
80+
requestAnimationFrame(() => {
81+
const { scale } = model;
82+
const [width, height] = publicAPI.getSize();
83+
model.svgRootNode.setAttribute(
84+
'viewBox',
85+
`0 0 ${width * scale} ${height * scale}`
86+
);
87+
model.svgRootNode.setAttribute('width', `${width * scale}`);
88+
model.svgRootNode.setAttribute('height', `${height * scale}`);
89+
for (let i = 0; i < model.widgets.length; i++) {
90+
model.widgets[i].render(model.svgRootNode, model.scale);
91+
}
92+
});
8893
}
8994
};
9095
}

0 commit comments

Comments
 (0)