LearningENVI&IDL分享 http://blog.sciencenet.cn/u/dongyanqing Learning ENVI&IDL

博文

idl图像显示程序(直接图形法与对象图形法混合显示)

已有 3522 次阅读 2011-4-16 15:11 |个人分类:IDL技术|系统分类:科研笔记| IDL, 程序编写

2011年4月IDL培训班(第三天)的图像显示程序代码(现场发挥版,多看注释)

;PRO abc,event
;  file = DIALOG_PICKFILE()
;  read_jpeg,file,data
;  tv,data,/true
;END
PRO MAIN_EVENT,event
  ;
  WIDGET_CONTROL, event.TOP,get_uvalue= str
 
  CASE WIDGET_INFO(event.ID,/uName) OF
    'seldraw1': BEGIN
      str.SELIDX=0
      WIDGET_CONTROL, event.TOP,Set_uvalue= str
    END
    'seldraw2': BEGIN
      str.SELIDX=1
      WIDGET_CONTROL, event.TOP,Set_uvalue= str
    END
    'OpenJPG': BEGIN
      file = DIALOG_PICKFILE(path = 'd:temp',filter='*.jpg')
      IF file EQ '' THEN RETURN;
      WIDGET_CONTROL, str.WFILELIST, set_value= file
    END
    'Show': BEGIN
      WIDGET_CONTROL, str.WFILELIST, get_value= file
      IF FILE_TEST(file) THEN BEGIN
     
        READ_JPEG,file,data
        ;   ;调用ENVI数据打开,则数据支持就无敌了,ENVI能打开的程序都能显示。
        ;        ENVI_OPEN_FILE, file, r_fid=fid
        ;        ENVI_FILE_QUERY, fid, dims=dims,ns= ns, nl =nl,DATA_TYPE = DATA_TYPE
        ;        ;
        ;        data  = make_array(3,ns,nl,TYPE = DATA_TYPE)
        ;        for i=0,2 do begin
        ;          data[i,*,*] =  ENVI_GET_DATA(fid=fid, dims=dims, pos=i)
        ;        endfor
       
        ;直接图形法
        IF str.SELIDX EQ 0 THEN  BEGIN
          ;WSET,str.WDRAW2
          str.OIMAGE->SETPROPERTY,/hide
          str.WDRAW2->DRAW,str.OVIEW
          ERASE
          WSET,str.WDRAW1
          TVSCL,data,/true
        ;tvscl,data
        ;对象图形法
        ENDIF  ELSE BEGIN
          WSET,str.WDRAW1
          ERASE
          str.OIMAGE->SETPROPERTY,data = data,hide=0
          str.WDRAW2->DRAW,str.OVIEW
        ENDELSE
      ENDIF
    END
    ELSE:
  ENDCASE
END
;析构函数
PRO MAIN_CLEANUP,tlb
  ;
  WIDGET_CONTROL, tlb,get_uvalue = str
  OBJ_DESTROY,str.OVIEW
 
END

PRO TEST_WIDGET1
  ;
  ;          wBase-2305
  ;          /                   
  ;    wControl2309    wbase       Bar 2306
  ;      /              /   
  ;  wButton  wButton  wDraw  wdraw
  ;  2310       2312
  wbase = WIDGET_BASE( $;xsize =800, $
    ;ysize =600,$
    /column, $
    mbar = bar)
  ;菜单
  wFile =WIDGET_BUTTON(bar, value= '文件(&F)')
  wOpen =WIDGET_BUTTON(wFile, value= '打开(&O)',$
    uname='OpenJPG')
  ;按钮
  wControl = WIDGET_BASE(wBase,/row,/frame)
  wbutton = WIDGET_BUTTON(wControl,value='打开jpeg',$
    uname='OpenJPG')
  ;,EVENT_PRO='abc')
  ;若button指定触发事件abc,则自动触发abc,event
  wFilelist = WIDGET_TEXT(wControl)
  wbutton1 = WIDGET_BUTTON(wControl,value='显示jpeg',uname='Show')
  ;显示控制
  wSelectbase = WIDGET_BASE(wControl,/EXCLUSIVE,$
    /row)
  wSelDraw1 = WIDGET_BUTTON(wSelectbase,value= 'selDraw1',$
    uname='seldraw1')
  wSelDraw2 = WIDGET_BUTTON(wSelectbase,value= 'selDraw2',$
    uname='seldraw2')
  WIDGET_CONTROL, wSelDraw1,/set_button
  ;显示
  wDrawBase = WIDGET_BASE(wBase, /row)
  wDraw1 = WIDGET_DRAW(wDrawBase,xsize = 400,ysize =400)
  wDraw2 = WIDGET_DRAW(wDrawBase,xsize = 400,ysize =400,$
    GRAPHICS_LEVEL = 2)
  ;
  WIDGET_CONTROL,wbase,/realize
  ;
  WIDGET_CONTROL,wDraw1,get_value = wDraw1ID
  WIDGET_CONTROL,wDraw2,get_value = wDraw2ID
  ;
  oImage = OBJ_NEW('IDLgrImage')
  oModel = OBJ_NEW('IDLgrModel')
  oView = OBJ_NEW('IDLgrView',viewplane_rect=[0,0,500,500])
  ;
  oVIew->ADD,oModel
  oModel->ADD,oImage
  ;用的结构体,一般用指针更好一些。
  struct = {wFilelist:wFilelist, $
    selIdx: 0b, $
    oImage: oImage, $
    oView:oView, $
    wDraw1: wDraw1ID,$
    wDraw2:wDraw2ID} ;IDLgrWindow对象
   
  WIDGET_CONTROL, wBase, set_uvalue = struct
  ;
  ;关联产生事件
  XMANAGER, 'main', wbase, /NO_BLOCK,$
    cleanUP = 'main_cleanup'
   
END


https://wap.sciencenet.cn/blog-344887-433911.html

上一篇:Lidar Tools for ENVI
下一篇:再讨论浮点运算精度问题(IDL与Excel和Matlab相比)

0

发表评论 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2022-1-28 14:23

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部