Skip to content

fix: Add requestAnimationFrame for Crosshairs SVG updates. Include la… #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/VTKCrosshairsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class VTKCrosshairsExample extends Component {

volumeActor.setMapper(volumeMapper);

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

Expand Down
Binary file not shown.
59 changes: 59 additions & 0 deletions public/vmhead2-large.vti/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"origin": [
0.0,
0.0,
0.0
],
"cellData": {
"arrays": [],
"vtkClass": "vtkDataSetAttributes"
},
"FieldData": {
"arrays": [],
"vtkClass": "vtkDataSetAttributes"
},
"vtkClass": "vtkImageData",
"pointData": {
"arrays": [
{
"data": {
"numberOfComponents": 1,
"name": "nrrd75611",
"vtkClass": "vtkDataArray",
"dataType": "Uint16Array",
"ranges": [
{
"max": 4095.0,
"component": null,
"min": 0.0
}
],
"ref": {
"encode": "LittleEndian",
"basepath": "data",
"id": "cd5fdd0a0c562d5753de2e8189c7fdf7",
"registration": "setScalars"
},
"size": 77070336
}
}
],
"vtkClass": "vtkDataSetAttributes"
},
"spacing": [
0.527344,
0.527344,
1.0
],
"extent": [
0,
511,
0,
511,
0,
293
],
"metadata": {
"name": "vmhead2-large.vti"
}
}
27 changes: 16 additions & 11 deletions src/VTKViewport/vtkSVGWidgetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ function vtkSVGWidgetManager(publicAPI, model) {

publicAPI.render = () => {
if (model.svgRootNode) {
const { scale } = model;
const [width, height] = publicAPI.getSize();
model.svgRootNode.setAttribute(
'viewBox',
`0 0 ${width * scale} ${height * scale}`
);
model.svgRootNode.setAttribute('width', `${width * scale}`);
model.svgRootNode.setAttribute('height', `${height * scale}`);
for (let i = 0; i < model.widgets.length; i++) {
model.widgets[i].render(model.svgRootNode, model.scale);
}
// TODO: Not sure this is the best approach but it seems to be
// making things smoother. Updating the DOM seemed to be
// the performance bottleneck for the crosshairs tool
requestAnimationFrame(() => {
const { scale } = model;
const [width, height] = publicAPI.getSize();
model.svgRootNode.setAttribute(
'viewBox',
`0 0 ${width * scale} ${height * scale}`
);
model.svgRootNode.setAttribute('width', `${width * scale}`);
model.svgRootNode.setAttribute('height', `${height * scale}`);
for (let i = 0; i < model.widgets.length; i++) {
model.widgets[i].render(model.svgRootNode, model.scale);
}
});
}
};
}
Expand Down