[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with IDLgrROI and normalization.



Erik Hummel (erik.hummel@philips.com) writes:

> In the program added an IDLgrPolyLine and IDLgrROI object are drawn. The
> results of the
> program is that only the IDLgrPolyLine is drawn. Important is that
> normalized coordinates are used,
> otherwise both objects are correctly drawn.
> What is wrong here?

I don't think there is anything wrong with *your* code.
I believe you have discovered a bug in the IDLgrROI
code. :-)

Here is an example. Two windows, produced with identical
code. However, the viewport rectangle in one window uses
a "device" coordinate system (0 to 500), whereas the
viewport rectangle in the second window uses a
"normalized" coordinate system (0 to 1). The ROI appears
in the first window, but not in the second. 

I'll report this to RSI and see what they have to say.

Cheers,

David
-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155

------------------------------------------------------
FUNCTION Normalize, range, Position=position

On_Error, 1
IF N_Params() EQ 0 THEN Message, 'Please pass range vector as argument.'

IF (N_Elements(position) EQ 0) THEN position = [0.0, 1.0] ELSE $
    position=Float(position)
range = Float(range)

scale = [((position[0]*range[1])-(position[1]*range[0])) / $
    (range[1]-range[0]), (position[1]-position[0])/(range[1]-range[0])]

RETURN, scale
END


PRO ROI_TEST
    
; Draw using viewport with device coordinates.


    top_wid  = Widget_Base(XSize = 500, YSize = 500, Title='Device 
Coordinates')

    draw_wid =  Widget_Draw(top_wid, XSize = 500, YSize = 500,$
      Graphics_Level = 2, Retain=2)

    Widget_Control, top_wid, /REALIZE;
    Widget_Control, draw_wid, Get_Value = window


    view = Obj_New('IDLgrView', Color = [100, 100, 100])
    view->SetProperty,Viewplane_rect = [0,0,500,500]

    model = Obj_New('IDLgrModel')
    view->Add, model

    ; The IDLgrROI Object.
    gfxROI = OBJ_New('IDLgrROI', [50, 400, 400, 50, 50], $
       [50, 50, 400, 400, 50], Color=[255,255,0])
    model->Add, gfxROI
    gfxROI->GetProperty, xrange=xrange, yrange=yrange
    Print, 'XRange for Device Coordinates: ', xrange
    Print, 'YRange for Device Coordinates: ', yrange
    xs = Normalize(xrange, Pos=[50,400])
    ys = Normalize(yrange, Pos=[50,400])
    gfxROI->SetProperty, XCoord_Conv = xs, YCoord_Conv = ys

    window->Draw, view

; Draw using veiwport with normalized coordinates.

    top_wid  = Widget_Base(XSize = 500, YSize = 500, $
      XOffset=500, YOffset=0, Title='Normalized Coordinates')

    draw_wid =  Widget_Draw(top_wid, XSize = 500, YSize = 500,$
      Graphics_Level = 2, Retain=2)

    Widget_Control, top_wid, /REALIZE;
    Widget_Control, draw_wid, Get_Value = window


    view = Obj_New('IDLgrView', Color = [100, 100, 100])
    view->SetProperty,Viewplane_rect = [0,0,1,1]

    model = Obj_New('IDLgrModel')
    view->Add, model

    ; The IDLgrROI Object.
    gfxROI = OBJ_New('IDLgrROI', [50, 400, 400, 50, 50],$
      [50, 50, 400, 400, 50], Color=[255,255,0])
    model->Add, gfxROI
    gfxROI->GetProperty, xrange=xrange, yrange=yrange
    Print, 'XRange for Normalized Coordinates: ', xrange
    Print, 'YRange for Normalized Coordinates: ', yrange
    xs = Normalize(xrange, Pos=[0.1,0.8])
    ys = Normalize(yrange, Pos=[0.1,0.8])
    gfxROI->SetProperty, XCoord_Conv = xs, YCoord_Conv = ys

    window->Draw, view
end