CW_DEFROI

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

Calling Sequence

Result = CW_DEFROI( Draw )

Arguments

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

Keywords

IMAGE_SIZE

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.

OFFSET

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

ORDER

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

RESTORE

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

ZOOM

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.

Keywords to WIDGET_CONTROL and WIDGET_INFO

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.

Example

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

ENDIF

IF ev.id EQ done THEN WIDGET_CONTROL, ev.top, /DESTROY
; Define what happens when you click the "Done" button.

END

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

 

END

 

See Also

DEFROI