The CW_DEFROI function creates a compound widget that allows the user to define a region of interest within a widget draw window.

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 in the lib subdirectory of the IDL distribution.

Calling Sequence

Result = CW_DEFROI( Draw )



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.


The offset of lower left corner of image within the draw window. Default = [0,0].


Set this keyword to return inverted subscripts, as if the array were output from top to bottom.


Set this keyword to restore the draw window to its previous appearance on exit. Otherwise, the regions remain on the drawable.


If the image array was expanded (using REBIN, for example) specify this two element vector containing the expansion factor in X and Y. Default = [1,1]. Both elements of ZOOM must be integers.


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 .

Widget Events Returned by the CW_DEFROI Widget

Region definition widgets do not return an event structure.


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:

PRO test_event, ev

COMMON T, draw, dbutt, done, image
; The common block holds variables that are shared between the routine and its event handler.

IF 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.

; 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.


; 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.

PRO test

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, 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.




See Also