38
Rolando V. Raqueño January 2006 1 1 Computing for Imaging Science (SIMG-726)

Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Embed Size (px)

DESCRIPTION

Rolando V. RaqueñoJanuary Assignment #1 Check Wiki for Due Dates Report must be generated using LaTeX –Use report document class Post LaTeX source and pdf file to wiki –Topic name should be WikiNameAssignment1 –JohnSmithAssignment1

Citation preview

Page 1: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200611

Computing for Imaging Science (SIMG-726)

Page 2: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200622

QUIZ Next Class

• Reading Assignment Topics

• Topics– Grep, cd, RCS commands, chmod, mkdir

Page 3: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200633

Assignment #1

• Check Wiki for Due Dates• Report must be generated using LaTeX

– Use report document class • Post LaTeX source and pdf file to wiki

– Topic name should be WikiNameAssignment1

– JohnSmithAssignment1

Page 4: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200644

Assignment #1 (Continued)

• Change protection of Wiki topic page for – Viewing and Modification only by

• You and• RolandoRaqueno

– TRY IT ON A TEST PAGE FIRST!– Refer to Wiki Topic

People.HowToRestrictWikiTopicAccess• Lastly,

– Put a link to your assignment in your wiki home page

Page 5: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200655

FINAL PRESENTATIONS

• PLEASE CHECK LINK ON CLASS WIKI• IT IS ON THE LAST DAY OF CLASS BUT

WILL START A EARLIER TO ACCOMMODATE EVERYONE

• PLEASE MAKE ARRANGEMENTS TO BE AVAILABLE

• LET ME KNOW OF ANY CLASS CONFLICTS

Page 6: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200666

Assignment #2

• (Check WIKI for Due date details)– Combine Assignment #1 into Assignment

#2– Create a program that will read in a PGM

file that will display the image statistics of a user defined rectangular region.

– Program the one-dimensional and two-dimensional special functions Rect and Gaus

Page 7: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200677

Widget Events

Page 8: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200688

Widget Event

• A widget event is basically a reaction to some form of user input– Mouse clicks, drags, and movement– Keyboard input– Button push

• An widget event generates a structure which identifies the widget that caused the event and other relevant information.

Page 9: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 200699

IDL Event Structure

• All IDL Events will generate a named structure that is guaranteed to have the following– A structure name– The ID of the widget that generated the event– The ID of the base to which the above widget

belongs– The ID of the widget with which an event handler is

associated.

Page 10: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061010

Event Handler

• Special Processing functions (Event Handlers) – capture and appropriately interpret those

events.• single button program

– beep when pressed.• First, need to create and destroy a

widget by creating a Quit Button

Page 11: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061111

Create the Quit Button Widget

pro quit_button

base=Widget_Base(column=1,title=“Quit Button”) button = Widget_Button( base, value=“Quit” ) Widget_Control, base, /realize

end

Page 12: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061212

Quit Button Widget Event Handler

Method #1pro quit_button_event, event Widget_Control, event.top, /destroyend

pro quit_button base=Widget_Base(column=1,title=“Quit Button”) button = Widget_Button( base, value=“Quit”) Widget_Control, base, /realize Xmanager, ’quit_button', base, event_handler=’quit_button_event'

end

Page 13: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061313

Quit Button Widget Event Handler Method #2

pro quitter, event Widget_Control, event.top, /destroyendpro quit_button_event, eventendpro quit_button base=Widget_Base(column=1,title=‘Quit Button’) button=Widget_Button(base, value=‘Quit’, event_pro=‘quitter’ )

Widget_Control, base, /realize Xmanager, ’quit_button', base,event_handler=’quit_button_event'end

Page 14: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061414

Button Widget Example

• For the sake of presentation space, we will not be including the quit button in the following code.

• You should, however, include it so that you can gracefully get rid of the widgets.

Page 15: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061515

Create the Button Widget

pro beeper

base=Widget_Base(column=1, title="Beep" ) button=Widget_Button(base,value="Press Here") Widget_Control, base, /realize

end

Page 16: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061616

Button Widget Event Handler

pro beeper_event, event print,"Beep",string(7B)end

pro beeper base=Widget_Base( column=1, title="Beep" ) button=Widget_Button(base,value="Press Here") Widget_Control, base, /realize Xmanager, 'beeper', base, event_handler='beeper_event'

end

Page 17: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061717

If Your Widget Program Crashes

• First type IDL> RETALL

• Followed byIDL> XMANAGER

• You may then edit and recompile as necessary

Page 18: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061818

Analyzing the Beep Event Handler

• You can strategically put help and print commands in beep_event and beep to study the values of the variables and the resulting structures.

• When pressed, the word Beep should print out in the IDL command window.

Page 19: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20061919

Beep Counter

• Let us modify the event handler to count the number of times we depressed the button during a session

• An initial solution might be the following

Page 20: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062020

Wrong Beep Counterpro beeper_event, event count = count + 1 print,”Beeped “, count, “ Times”end

pro beeper base=Widget_Base(column=1, title="Beep") button=Widget_Button(base,value="Press Here") Widget_Control, base, /realize Xmanager, 'beeper', base, event_handler='beeper_event'

end

Page 21: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062121

It Does Not Work Because...

• The scope of most of the variables (e.g. count) are local to each of the routines.

• We need a mechanism to maintain, pass, and keep variables persistent across events and routines.

• This can be done using the uvalue of a given widget as in the following.

Page 22: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062222

Working Beep Counterpro beeper_event, event

Widget_Control,event.id,get_uvalue=count count = count + 1 print,"Beeped ", count, " Times"

Widget_Control,event.id,set_uvalue=countend

pro beeper base = Widget_Base( column=1, title="Beep" ) button = Widget_Button( base, value="Press Here" ) Widget_Control, base, /realize

Widget_Control,button,set_uvalue=0 Xmanager, 'beeper', base, event_handler='beeper_event'end

Page 23: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062323

An Improved Beep Counterpro beeper_event, event Widget_Control, event.id, get_uvalue=count count = count + 1

Widget_Control, event.id, set_uvalue=count Widget_Control, event.id, set_value=string(count)end

pro beeper base = Widget_Base( column=1, title="Beep" ) button = Widget_Button( base, value="Press Here" ) Widget_Control, base, /realize Widget_Control, button, set_uvalue=0 Xmanager, 'beeper', base, event_handler='beeper_event'end

Page 24: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062424

Beep Counter Controlling a Text Widget

pro beeper_event, event Widget_Control, event.id, get_uvalue=count count = count + 1 Widget_Control, event.id, set_uvalue=count

Widget_Control, event.top, get_uvalue=widget_id Widget_Control, widget_id, set_value=string(count)end

pro beeper base = Widget_Base( column=1, title="Beep" ) button = Widget_Button( base, value="Press Here" ) text = Widget_Text( base ) Widget_Control, base, /realize

Widget_Control, base, set_uvalue=text Widget_Control, button, set_uvalue=0 Xmanager, 'beeper', base, event_handler='beeper_event'end

Page 25: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062525

Beeper Counter using Text Widget

• In this situation, we use the uvalue of the base widget as a container to hold the ID of the text widget.

• We can now access this information from any widget that is contained in this base through the event.top field

Page 26: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062626

Slider Multiply Example

• Create two floating sliders and multiply the values and deposit this in a text widget.

• Make the floating point widgets editable

Page 27: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062727

Slider Multiply Widget Definition

pro fslider_multiply base=Widget_Base(column=1) fslider1 = CW_Fslider(base,/edit) fslider2 = CW_Fslider( base,/edit ) text= Widget_Text( base ) Widget_Control, base, /realize widget_ids = { slider1:fslider1, slider2:fslider2, text:text }

Widget_Control, base, set_uvalue=widget_idsend

Page 28: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062828

Slider Multiply Event Handler Definition

pro fslider_multiply base=Widget_Base(column=1) fslider1 = CW_Fslider(base,/edit) fslider2 = CW_Fslider( base,/edit ) text= Widget_Text( base ) Widget_Control, base, /realize widget_ids = { slider1:fslider1, slider2:fslider2, text:text }

Widget_Control, base, set_uvalue=widget_idsXmanager, 'fslider_multiply', base, event_handler='fslider_multiply_event'

end

Page 29: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20062929

Slider Multiply Event Handler Definition

pro fslider_multiply_event, event Widget_Control, event.top, get_uvalue=widgets slider1 = widgets.slider1 slider2 = widgets.slider2 text = widgets.text Widget_Control, slider1, get_value=slider1_value Widget_Control, slider2, get_value=slider2_value answer= slider1_value * slider2_value Widget_Control, text, set_value=string(answer)end

Page 30: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063030

Another Widget Example

Page 31: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063131

Display PGM Widget Program

• Illustrates the use of the pickfile function

• Shows how to create a draw widget for image display

• Shows how to access the draw widget and display the image

Page 32: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063232

Components of Display PGM Widget

• read_pgm procedure• pickfile function• size function• wset procedure• tv procedure• widget_control procedure• widget_draw function• xmanager procedure

Page 33: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063333

Display PGM Widget Definition

pro simple_image_display base = Widget_Base( column=1 ) button1=Widget_Button(base,value='Display PGM Image') window1 = Widget_Draw(base, xsize=256, ysize=256 ) Widget_Control, window1, /realize Widget_Control, window1, get_value=window_id Widget_Control, base, set_uvalue=window_id Xmanager, 'simple_image_display', base,

Event_handler='simple_image_display_event'end

Page 34: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063434

Display PGM Widget

Page 35: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063535

Widget Event Handlerpro simple_image_display_event, event widget_control, event.id, get_value=widget_value case widget_value of 'Display PGM Image' : begin image1_file = pickfile() read_ppm, image1_file, image1_data image_size = size( image1_data ) x_size = image_size( 1 ) & y_size=image_size(2) widget_control, event.top, get_uvalue=window_id

wset, window_id & tv,image1_data end ELSE: endcaseend

Page 36: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063636

Pickfile Dialog Box

Page 37: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063737

Resulting Widget Image Display

Page 38: Rolando V. RaqueñoJanuary 2006 1 Computing for Imaging Science (SIMG-726)

Rolando V. Raqueño January 20063838

Summary

• Quit Button• Beep Counter• Slider Multiply• PGM Display