The CW_DEFROI function creates a compound widget that allows the user to define a region of interest within a widget draw window.
CAUTION: This is a modal widget. No other widget applications will be responsive while this widget is in use. Also, since CW_DEFROI has its own event-handling loop, it should not be created as a child of a modal base.
The returned value of this function is an array of subscripts defining the region. If no region is defined, the scalar -1 is returned.
This routine is written in the IDL language. Its source code can be found in the file
cw_defroi.pro
in the
lib
subdirectory of the IDL distribution.
The widget ID of draw window in which to draw the region. Note that the draw window must have both BUTTON and MOTION events enabled (see WIDGET_DRAW for more information).
The size of the underlying array, expressed as a two element vector: [ columns , rows ]. Default is the size of the draw window divided by the value of ZOOM.
Set this keyword to return inverted subscripts, as if the array were output from top to bottom.
The widget ID returned by most compound widgets is actually the ID of the compound widget's base widget. This means that many keywords to the WIDGET_CONTROL and WIDGET_INFO routines that affect or return information on base widgets can be used with compound widgets.
See Compound Widgets for a more complete discussion of controlling compound widgets using WIDGET_CONTROL and WIDGET_INFO .
The following two procedures create a region-of-interest widget and its event handler. Create a file containing the program code using a text editor and compile using the .RUN command, or type .RUN at the IDL prompt and enter the lines interactively.
First, create the event handler:
COMMON T, draw, dbutt, done, image
;
The common block holds variables that are shared between the routine and its event handler.
IF ev.id EQ dbutt THEN BEGIN ; Define what happens when you click the "Draw ROI" button.
Q = CW_DEFROI(draw) ; The ROI definition will be stored in the variable Q.
HELP, Q ; Show the size of the ROI definition array.
image2 = image ; Duplicate the original image.
image2(Q)=!P.COLOR-1 ; Set the points in the ROI array Q equal to a single color value.
WIDGET_CONTROL, draw, GET_VALUE=W
;
Get the window ID of the draw widget.
WSET, W ; Set the draw widget as the current graphics window.
TV, image2 ; Load the image plus the ROI into the draw widget.
IF ev.id EQ done THEN WIDGET_CONTROL, ev.top, /DESTROY
;
Define what happens when you click the "Done" button.
Next, create a draw widget that can call CW_DEFROI. Note that you must specify both button events and motion events when creating the draw widget, if it is to be use with CW_DEFROI.
COMMON T, draw, dbutt, done, image
base = WIDGET_BASE(/COLUMN) ; Create a base to hold the draw widget and buttons.
draw = WIDGET_DRAW(base, XSIZE=256, YSIZE=256, /BUTTON, /MOTION)
;
Create a draw widget that will return both button and motion events.
dbutt = WIDGET_BUTTON(base, VALUE='Draw ROI')
done = WIDGET_BUTTON(base, VALUE='Done')
WIDGET_CONTROL, base, /REALIZE
WIDGET_CONTROL, draw, GET_VALUE=W ; Get the widget ID of the draw widget.
WSET, W ; Set the draw widget as the current graphics window.
image = BYTSCL(SIN(DIST(256))) ; Create an original image.
TV, image ; Display the image in the draw widget.
XMANAGER, "test", base ; Start XMANAGER.