Skip to content
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
7 changes: 7 additions & 0 deletions examples/volume-viewer-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ $(function() {
});
});

$(document).keypress(function(e) {
if (e.keyCode === 114) {
// Reset displays if user presses 'r' key.
viewer.resetDisplays();
viewer.redrawVolumes();
}
});
//////////////////////////////////
// Per volume UI hooks go in here.
//////////////////////////////////
Expand Down
12 changes: 8 additions & 4 deletions src/brainbrowser/volume-viewer/lib/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@
* ```
*/
reset: function() {
panel.zoom = 1;
panel.zoom = panel.default_zoom;
panel.image_center.x = panel.canvas.width / 2;
panel.image_center.y = panel.canvas.height / 2;
panel.updated = true;
},

/**
Expand Down Expand Up @@ -496,7 +497,10 @@
}

if (panel.volume) {
setSlice(panel, panel.volume.slice(panel.axis));
var volume = panel.volume;
setSlice(panel, volume.slice(panel.axis));
panel.default_zoom = volume.getPreferredZoom(panel.canvas.width, panel.canvas.height);
panel.zoom = panel.default_zoom;
}

return panel;
Expand All @@ -517,7 +521,7 @@
var context = panel.context;
var cursor = panel.getCursorPosition();
var zoom = panel.zoom;
var length = 8 * zoom;
var length = 8 * (zoom / panel.default_zoom);
var x, y, space;
var distance;
var dx, dy;
Expand All @@ -528,7 +532,7 @@
context.strokeStyle = color;
context.fillStyle = color;

space = zoom;
space = 1;
x = cursor.x;
y = cursor.y;

Expand Down
5 changes: 3 additions & 2 deletions src/brainbrowser/volume-viewer/modules/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {

last_touch_distance = null;
}

canvas.addEventListener("mousedown", function(event) {
event.preventDefault();

Expand Down Expand Up @@ -696,7 +696,8 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
}

function zoom(delta) {
panel.zoom = Math.max(panel.zoom + delta * 0.05, 0.05);
panel.zoom *= (delta < 0) ? 1/1.05 : 1.05;
panel.zoom = Math.max(panel.zoom, 0.25);
panel.updateVolumePosition();
panel.updateSlice();

Expand Down
15 changes: 15 additions & 0 deletions src/brainbrowser/volume-viewer/volume-loaders/minc.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,21 @@
},
getVoxelMax: function() {
return volume.header.voxel_max;
},
/* given a width and height (from the panel), this function returns the "best"
* single zoom level that will guarantee that the image fits exactly into the
* current panel.
*/
getPreferredZoom: function(width, height) {
var header = volume.header;
var x_fov = header.xspace.space_length * Math.abs(header.xspace.step);
var y_fov = header.yspace.space_length * Math.abs(header.yspace.step);
var z_fov = header.zspace.space_length * Math.abs(header.xspace.step);
var xw = width / x_fov;
var yw = width / y_fov;
var yh = height / y_fov;
var zh = height / z_fov;
return Math.min(yw, xw, zh, yh);
}
};
return volume;
Expand Down