PRO qImage_TrackPeak, state ;+ ; NAME: ; qImage_TrackPeak ; PURPOSE: ; Assist qView widget in tracking of a peak through a sequence of images. ; CATEGORY: ; Widget qImage ; CALLING SEQUENCE: ; qImage_TrackPeak, state ; INPUTS: ; state array[1]; type: structure ; qImage state structure ; OUTPUTS: ; (event send back to qView) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; BadValue, qImage_cw_Box, qImage_cw_Update, flat_centerofmass ; PROCEDURE: ; MODIFICATION HISTORY: ; FEB-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- wid_child = widget_info(state.wid_qimage_cw, /child) widget_control, wid_child, get_uvalue=qimage_cw_state, /no_copy ; boxes[*,0,0] (and boxes[*,1,0]) contains the previous centroid. ; boxes[*,*,1] is the box to be centered on this centroid. ; If smei_set=1 then 'boxes' will be in polar coordinates relative to smei_center. ; If smei_set=0 then 'boxes' is in rectangular coordinates centroid = double(state.boxes[*,0,0]) ; Previous centroid box = double(state.boxes[*,*,1]) ; Box template widget_control, qimage_cw_state.wid_smei, get_uvalue=smei_set CASE smei_set OF 0: centroid = centroid-qimage_cw_state.img_offset 1: qImage_cw_Box, qimage_cw_state, smei_center, /center ENDCASE dr_max = 0.1 nn_max = 10 nn = 0 REPEAT BEGIN prev_centroid = centroid ; Center of box (polar or rectangular) ; Center box on centroid tmp = flat_centerofmass(box, prev_centroid, polar=smei_set) CASE smei_set OF 0: qImage_cw_Box, qimage_cw_state, tmp, /put 1: qImage_cw_Box, qimage_cw_state, p_box=tmp, /polar, /put ENDCASE qImage_cw_Update, qimage_cw_state ; Update the widget ; Get double precision centroid in rectangular coordinates widget_control, qimage_cw_state.wid_xyz[8], get_uvalue=centroid CASE finite(centroid[0]) OF 0: nn = nn_max 1: BEGIN ; Make sure centroid is available centroid = centroid-qimage_cw_state.img_offset ; Subtract image offset CASE smei_set OF 0: dr = centroid-prev_centroid 1: BEGIN centroid = centroid-smei_center ; Centroid relative to smei_center dr = centroid-cv_coord(from_polar=prev_centroid, /to_rect) centroid = cv_coord(from_rect=centroid, /to_polar) ; Centroid in polar coordinates END ENDCASE dr = sqrt( total(dr*dr) ) ; Distance of centroid to box center nn = nn+1 print, 'optimizing>>: ', nn, dr END ENDCASE ENDREP UNTIL dr LT dr_max OR nn GE nn_max ; If new centroid to far away from center, iterate ; Pick up centroid information widget_control, qimage_cw_state.wid_xyz[8], get_uvalue=centroid track = finite(centroid[0]) ; Centroid in rectangular coordinates CASE track OF 0: BEGIN Bad = BadValue(0.0) zval = replicate(Bad, 4) zback = Bad zpix = replicate(Bad, 2) peak = 0B END 1: BEGIN ; Centroid available zval = fltarr(4, /nozero) FOR i=0,3 DO BEGIN ; min, max, avg, stdv widget_control, qimage_cw_state.wid_xyz[4+i], get_value=tmp zval[i] = tmp ENDFOR widget_control, qimage_cw_state.wid_xyz[9], get_uvalue=zpix zback = zpix[0] ; Background used for centroid calculation zpix = zpix[1:2] ; # pixels in background and central region peak = (zval[1]-zval[2])/(zval[2]-zval[0]) GT 1 END ENDCASE widget_control, wid_child, set_uvalue=qimage_cw_state, /no_copy ; Set up the message to be send back to the qView widget. widget_control, state.wid_send, get_uvalue=receive widget_control, receive[0], send_event={QIMAGE_TRACK,ID:0L,TOP:0L,HANDLER:0L, $ TRACKING:track, PEAK:peak, CENTROID:centroid, ZVAL:zval, ZBACK:zback, ZPIX:zpix} RETURN & END