Skip to content

Commit cf79ab1

Browse files
committed
Merge pull request #299 from rdvincent/rdv-zoom
Several changes to improve zooming behaviour.
2 parents 300cac4 + 4c1e83c commit cf79ab1

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

examples/volume-viewer-demo.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ $(function() {
285285
});
286286
});
287287

288+
$(document).keypress(function(e) {
289+
if (e.keyCode === 114) {
290+
// Reset displays if user presses 'r' key.
291+
viewer.resetDisplays();
292+
viewer.redrawVolumes();
293+
}
294+
});
288295
//////////////////////////////////
289296
// Per volume UI hooks go in here.
290297
//////////////////////////////////

src/brainbrowser/volume-viewer/lib/panel.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@
295295
* ```
296296
*/
297297
reset: function() {
298-
panel.zoom = 1;
298+
panel.zoom = panel.default_zoom;
299299
panel.image_center.x = panel.canvas.width / 2;
300300
panel.image_center.y = panel.canvas.height / 2;
301+
panel.updated = true;
301302
},
302303

303304
/**
@@ -496,7 +497,10 @@
496497
}
497498

498499
if (panel.volume) {
499-
setSlice(panel, panel.volume.slice(panel.axis));
500+
var volume = panel.volume;
501+
setSlice(panel, volume.slice(panel.axis));
502+
panel.default_zoom = volume.getPreferredZoom(panel.canvas.width, panel.canvas.height);
503+
panel.zoom = panel.default_zoom;
500504
}
501505

502506
return panel;
@@ -517,7 +521,7 @@
517521
var context = panel.context;
518522
var cursor = panel.getCursorPosition();
519523
var zoom = panel.zoom;
520-
var length = 8 * zoom;
524+
var length = 8 * (zoom / panel.default_zoom);
521525
var x, y, space;
522526
var distance;
523527
var dx, dy;
@@ -528,7 +532,7 @@
528532
context.strokeStyle = color;
529533
context.fillStyle = color;
530534

531-
space = zoom;
535+
space = 1;
532536
x = cursor.x;
533537
y = cursor.y;
534538

src/brainbrowser/volume-viewer/modules/loading.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
646646

647647
last_touch_distance = null;
648648
}
649-
649+
650650
canvas.addEventListener("mousedown", function(event) {
651651
event.preventDefault();
652652

@@ -696,7 +696,8 @@ BrainBrowser.VolumeViewer.modules.loading = function(viewer) {
696696
}
697697

698698
function zoom(delta) {
699-
panel.zoom = Math.max(panel.zoom + delta * 0.05, 0.05);
699+
panel.zoom *= (delta < 0) ? 1/1.05 : 1.05;
700+
panel.zoom = Math.max(panel.zoom, 0.25);
700701
panel.updateVolumePosition();
701702
panel.updateSlice();
702703

src/brainbrowser/volume-viewer/volume-loaders/minc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,21 @@
372372
},
373373
getVoxelMax: function() {
374374
return volume.header.voxel_max;
375+
},
376+
/* given a width and height (from the panel), this function returns the "best"
377+
* single zoom level that will guarantee that the image fits exactly into the
378+
* current panel.
379+
*/
380+
getPreferredZoom: function(width, height) {
381+
var header = volume.header;
382+
var x_fov = header.xspace.space_length * Math.abs(header.xspace.step);
383+
var y_fov = header.yspace.space_length * Math.abs(header.yspace.step);
384+
var z_fov = header.zspace.space_length * Math.abs(header.xspace.step);
385+
var xw = width / x_fov;
386+
var yw = width / y_fov;
387+
var yh = height / y_fov;
388+
var zh = height / z_fov;
389+
return Math.min(yw, xw, zh, yh);
375390
}
376391
};
377392
return volume;

0 commit comments

Comments
 (0)