File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed
src/brainbrowser/volume-viewer Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff 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 //////////////////////////////////
Original file line number Diff line number Diff line change 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 /**
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 ;
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 ;
528532 context . strokeStyle = color ;
529533 context . fillStyle = color ;
530534
531- space = zoom ;
535+ space = 1 ;
532536 x = cursor . x ;
533537 y = cursor . y ;
534538
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments