FUNCTION qImage_cw_Transform, state, $ fromimage=FromImage, fromscreen=FromScreen, frombigimage=FromBigImage, $ toimage=ToImage, toscreen=ToScreen, tobigimage=ToBigImage, $ parent=parent, boxedge=boxedge, zoom=zoom, origin=origin ;+ ; NAME: ; qImage_cw_Transform ; PURPOSE: ; Coordinate transformation needed by qImage_cw widget ; CATEGORY: ; Compound widget qImage_cw ; CALLING SEQUENCE: ; pnt_out = qImage_cw_Transfor(state, fromimage=pnt_in, /toscreen) ; INPUTS: ; state array[1]: type: structure ; state structure of the qImage_cw compound widget ; OPTIONAL INPUT PARAMETERS: ; One of the following three MUST be specified: ; The units for all positions are the indices of the corresponding arrays. ; ; FromImage array[2], array[2,n]; type: integer or float ; x and y position on the image displayed ; FromScreen array[2], array[2,n]; type: integer or float ; FromBigImage array[2], array[2,n]; type: integer or float ; ; Only one of the following should be specified ; /toimage Convert to Image coordinates ; /tobigimage Convert to BigImage coordinates ; /toscreen Convert to Screen coordinates ; /image is the default if none is specified ; ; /parent Only used when transforming TO Image coordinates ; i.e. if /toimage is set. ; If set then Screen or BigImage input coordinates are ; converted to the parent pixels in the original image in ; which they lie (this amounts to a 'round' operation). ; /boxedge Should only be used when transforming a box (an integer 2x2 ; element vector of the form [[xmin,ymin],[ymin,ymax]]) ; in Image coordinates to Screen or BigImage coordinates. ; The result is a box in Screen or BigImage coordinates ; which bounds the area represented by the Image box. ; OUTPUTS: ; pnt_out array[2] or array[2,*]; type: float ; requested coordinates. The array will have the same structure ; as the input array ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; SyncDims, InitVar, IsType ; PROCEDURE: ; > Image[n,m]: this is the image fed to the qImage_cw ; (stored in the user value of state.wid_image) ; ; BigImage[N,M]: this is a magnified version of the input Image ; For magnification with factor zoom: N=zoom*n, M=zoom*m ; The zoom factor is stored in the struct in the user value of state.wid_tool. ; The coordinates of BigImage are related to the coordinates in Image by: ; ; pnt(BigImage) = (zoom-1)/2.0+zoom*pnt(Image) ; ; If zoom is odd then a pixel in Image (with integer coordinate values) ; is mapped exactly to a pixel in BigImage. ; ; If zoom is even then each pixel in Image is mapped midway between to ; pixels in the BigImage array. ; ; Screen[n,m]: this is the section of BigImage that is being displayed. ; ; STATE INFO USED: ; widget_control, state.wid_tool, get_uvalue=tool ; STATE INFO MODIFIED: ; None ; ; MODIFICATION HISTORY: ; FEB-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- Image = IsType(FromImage , /defined) BigImage = IsType(FromBigImage, /defined) Screen = IsType(FromScreen , /defined) InitVar, ToScreen , /key InitVar, ToBigImage , /key InitVar, ToImage , (ToScreen+ToBigImage) EQ 0 InitVar, Parent , /key InitVar, BoxEdge, /key ; Pick up information from state vector ; Origin is a pair of array indices in the magnified/minified image. IF IsType(zoom, /undefined) THEN BEGIN widget_control, state.wid_tool, get_uvalue=tool_state, /no_copy zoom = tool_state.send.zoom_uval widget_control, state.wid_tool, set_uvalue=tool_state, /no_copy ENDIF IF IsType(origin, /undefined) THEN origin = qImage_cw_Property(state, /slider_origin) ; Pick up the input array (input is not modified) CASE 1 OF Image : pnt = FromImage BigImage: pnt = FromBigImage Screen : pnt = FromScreen ENDCASE sz_pnt = size(pnt) ; Save input size vector (output is in same form) n_pnts = sz_pnt[sz_pnt[0]+2]/2 ; # locations pnt = reform(pnt,2,n_pnts,/overwrite) ; Make sure pnt is [2,*] (needed if n_pnts=1) one = replicate(1,n_pnts) ; Auxilliary stuff origin = origin#one pixel = [[-1,-1],[1,1]]/2.0 ; Pixel centered on [0,0] IF BoxEdge THEN pnt = pnt+pixel ; Add half pixel to either side of the box CASE 1 OF ; Transform to Image coordinates Image : BigImage: pnt = (pnt-(zoom-1)/2.0)/zoom ; -> Image Screen : pnt = (pnt+origin-(zoom-1)/2.0)/zoom ; -> BigImage (add origin) -> Image ENDCASE CASE 1 OF ; Image -> Destination coord ToImage: BEGIN IF BoxEdge THEN pnt = pnt-pixel IF Parent THEN pnt = round( pnt ) ; To Image END ToBigImage: BEGIN pnt = (zoom-1)/2.0+zoom*pnt IF BoxEdge THEN pnt = round(pnt-pixel) ; Take off half a pixel to get pixel centers END ToScreen: BEGIN pnt = (zoom-1)/2.0+zoom*pnt-origin IF BoxEdge THEN pnt = round(pnt-pixel) ; Take off half a pixel to get pixel centers END ENDCASE SyncDims, pnt, size=sz_pnt RETURN, pnt & END