PRO qImage_cw_BoxZoom, state, sub_img, sub_box, screen, zoom, nrebin, xzoom=xzoom, yzoom=yzoom ;+ ; NAME: ; qImage_cw_BoxZoom ; PURPOSE: ; Prepare zoomed part of image that fits on screen ; CATEGORY: ; CALLING SEQUENCE: ; INPUTS: ; state array[1]; type: structure ; qImage_cw state structure ; sub_img array[n,m]; type: any ; part of original image to be put on screen ; sub_box array[2,2]; type: integer ; box with indices of part of original image ; stored in sub_img ; screen array[2]; type: integer ; screen size (# hor and vert pixels) ; zoom scalar; type: integer ; the zoom factor (can be < 0) ; OPTIONAL INPUT PARAMETERS: ; /xzoom ; /yzoom ; OUTPUTS: ; sub_img array[n,m]; type: any ; sub_box box with location on screen where sub_img is ; to put. ; OPTIONAL OUTPUT PARAMETERS: ; INCLUDE: @compile_opt.pro ; On error, return to caller ; EXTERNAL: ; CALLS: ; InitVar, MagnifyArray ; PROCEDURE: ; MODIFICATION HISTORY: ; MAY-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, xzoom, /key InitVar, yzoom, /key CASE 1 OF xzoom: BEGIN ; Horizontal cross-section IF size(sub_img,/n_dim) EQ 2 THEN BEGIN ; 2D sub_img sub_cnt = finite(sub_img) sub_img = total(sub_img,2,/nan) ; Sum over y-dim sub_cnt = total(sub_cnt,2) n = where(sub_cnt NE 0) ; Average over y-dim IF n[0] NE -1 THEN sub_img[n] = sub_img[n]/sub_cnt[n] ENDIF IF nrebin NE 1 THEN sub_img = smooth(sub_img,nrebin,/nan) CASE 1 OF zoom EQ 1: zoom GT 1: sub_img = MagnifyArray(sub_img, zoom) zoom LT 1: BEGIN n = size(sub_img,/dim) z = round(1.0/zoom) dbox = n-n/z*z IF dbox NE 0 THEN BEGIN n = n-dbox sub_img = sub_img[0:n-1] sub_box = sub_box-[0,0,dbox,0] ENDIF sub_img = rebin(sub_img,n/z) END ENDCASE sub_box = qImage_cw_Transform(state, fromimage=sub_box, /boxedge, /toscreen) sub_box = sub_box[[0,2]] dbox = [-sub_box[0] > 0, (screen[0]-1-sub_box[1]) < 0] IF (where(dbox NE 0))[0] NE -1 THEN BEGIN sub_img = sub_img[dbox[0]:size(sub_img,/dim)-1+dbox[1]] sub_box = sub_box+dbox ENDIF END yzoom: BEGIN ; Vertical cross section IF size(sub_img,/n_dim) EQ 2 THEN BEGIN ; 2D sub_img sub_cnt = finite(sub_img) sub_img = total(sub_img,1,/nan) ; Sum over x-dim sub_cnt = total(sub_cnt,1) n = where(sub_cnt NE 0) ; Average over x-dim IF n[0] NE -1 THEN sub_img[n] = sub_img[n]/sub_cnt[n] ENDIF IF nrebin NE 1 THEN sub_img = smooth(sub_img,nrebin,/nan) CASE 1 OF zoom EQ 1: zoom GT 1: sub_img = MagnifyArray(sub_img, zoom) zoom LT 1: BEGIN n = size(sub_img,/dim) z = round(1.0/zoom) dbox = n-n/z*z IF dbox NE 0 THEN BEGIN n = n-dbox sub_img = sub_img[0:n-1] sub_box = sub_box-[0,0,0,dbox] ENDIF sub_img = rebin(sub_img,n/z) END ENDCASE sub_box = qImage_cw_Transform(state, fromimage=sub_box, /boxedge, /toscreen) sub_box = sub_box[[1,3]] dbox = [-sub_box[0] > 0, (screen[1]-1-sub_box[1]) < 0] IF (where(dbox NE 0))[0] NE -1 THEN BEGIN sub_img = sub_img[dbox[0]:size(sub_img,/dim)-1+dbox[1]] sub_box = sub_box+dbox ENDIF END ELSE: BEGIN IF nrebin NE 1 THEN sub_img = smooth(sub_img,nrebin,/nan) CASE 1 OF zoom EQ 1: zoom GT 1: sub_img = MagnifyArray(sub_img, zoom) zoom LT 1: BEGIN n = size(sub_img,/dim) z = round(1.0/zoom) dbox = n-n/z*z IF (where(dbox NE 0))[0] NE -1 THEN BEGIN n = n-dbox sub_img = sub_img[0:n[0]-1,0:n[1]-1] sub_box = sub_box-[0,0,dbox] ENDIF sub_img = rebin(sub_img,n/z) END ENDCASE sub_box = qImage_cw_Transform(state, fromimage=sub_box, /boxedge, /toscreen) dbox = [-sub_box[0:1] > 0, (screen-1-sub_box[2:3]) < 0] IF (where(dbox NE 0))[0] NE -1 THEN BEGIN n = size(sub_img,/dim) ; Should be size sub_box*zoom sub_img = sub_img[dbox[0]:n[0]-1+dbox[2], dbox[1]:n[1]-1+dbox[3]] sub_box = sub_box+dbox ENDIF END ENDCASE RETURN & END