FUNCTION qImage_cw_Ellipse, state, box, edge=edge, noupdate=noupdate ;+ ; NAME: ; qImage_cw_Ellipse ; PURPOSE: ; Calculate boundary and bounding box for a wedge specified as two points ; in polar coordinates ; CATEGORY: ; Compound widget qImage_cw ; CALLING SEQUENCE: ; Result = qImage_cw_Wedge(state, p_box, ) ; INPUTS: ; state array[1]; type: structure ; qImage_cw state structure ; OPTIONAL INPUT PARAMETERS: ; p_box array[2,2]; type: float ; limiting values in phase angle and radius of the wedge ; in the form [[angle1,radius1],[angle2,radius2]]. ; Angle1 and angle2 are in radians between [-!pi,+!pi]. ; The wedge runs counterclockwise from 'angle1' to 'angle2' ; over less than 180 degrees: either angle2 > angle1 with ; angle2-angle1 < !pi or angle2 < angle1 with ; angle+2*!pi-angle1 < !pi. Always radius1 < radius2. ; ; If polar_box is not specified then the wedge specified in ; the qImage_cw widget is used. ; ; If polar_box is specified then the value is processed by qImage_cw_Box. ; This will update the qImage_cw widget, but will also slightly modify ; polar_box in such a way that the two corners of the wedge coincide with ; integer pixel locations (the values returned in 'box') ; (set /noupdate to bypass this step) ; /noupdate Only used if polar_box is specified. Bypasses a call to ; qImage_cw_Box (which updates the position widgets). ; OUTPUTS: ; result array[2,2]; type: integer ; corners of the smallest square in the image that completely encloses ; the wedge in pixel coordinates in the form [[x1,y1],[x2,y2]. ; Always x1 <= x2, y1 <= y2. ; OPTIONAL OUTPUT PARAMETERS: ; wedge array[2,n]; type: float ; boundary of wedge as a closed array (first=last point) ; in rectangular (pixel) coordinates. ; box array[2,2]; type: float; default: content of X,Y position widgets in ; qImage_cw. Two points in the image plane, specified as pixel coordinate ; values in the same form as the bounding box. ; 'box' is obtained by a call to qImage_cw_Box, and is not modified. ; If /noupdate is set then qImage_cw_Box is not called and 'box' will be undefined. ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, qImage_cw_Box ; PROCEDURE: ; The origin of the rectangular to polar transformation is the value of ; the state.wid_center widgets ; If p_box is specified, and keywords /noupdate and img_center are used then the state structure ; is not accessed. ; STATE INFO USED: ; STATE INFO MODIFIED: ; (none) ; MODIFICATION HISTORY: ; FEB-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, noupdate, /key CASE 1 OF IsType(box,/undefined): qImage_cw_Box, state, box, /get 1-noupdate : qImage_cw_Box, state, box, /put ELSE: ENDCASE n = 101 one = replicate(1,n) p = p_box[0]+(p_box[2]+(2*!pi)*fix(p_box[2] lt p_box[0])-p_box[0])*findgen(n)/(n-1) wedge = [ [ p,reverse(p),p[0]], [ p_box[1]*one,p_box[3]*one,p_box[1]] ] ; x,y coordinates of wedge IF n_elements(img_center) EQ 0 THEN qImage_cw_Box, state, img_center, /center wedge = img_center#replicate(1,2*n+1)+cv_coord(from_polar=transpose(wedge), /to_rect) ; Calculate the quadrant (1,2,3,4) quadrant = 1+fix(( (p_box[[0,2]]+2*!pi) mod (2*!pi))/(!pi/2)) IF quadrant[1] LT quadrant[0] THEN quadrant[1] = quadrant[1]+4 x = p_box[[1,3]]#cos(p_box[[0,2]]) y = p_box[[1,3]]#sin(p_box[[0,2]]) b_box = [ [min(x), min(y)], [max(x), max(y)] ] r = p_box[3] RETURN, box & END