Author: Daryl Atencio / Thursday, February 25, 2016
A recent project I worked on required an ENVI extension to respond ROI changes made in the ENVI Layer Manager. Fortunately, ENVI provides a mechanism that allows an object to do this. First, the object must be added to the list of observers for each ROI layer. The following command provides access to these layers:
IDLcf$Get , /INCLUDE_VIS_CHILDREN, VIS_LAYERS=oVisLayers
The variable oVisLayers will contain all visible layers present in the ENVI display. To get only the ROIs, loop through its contents looking for any instances of IDLcfVisROINative. When one is encountered the object can be added to the ROI layer’s list of observers using the following:
void = oVisLayers[i]-> AddObserver (self)
Now that the object has been added to the list of observers an OnNotify method must be added. Any notifications from the ROI layers will be sent to this method.
function my_class ::OnNotify, oSubject, strMsg, strArg
The input parameters are:\
Here is a stand-alone example that demonstrates setting up an object to receive and act on notifications from ROIs in the ENVI Layer Manager:
;##############################################################################
; This example demonstrates how to get notifications from ENVI when changes are
; made to ROIs in the Layer Manager.
;------------------------------------------------------------------------------
;+
; Event handler used by XMANAGER
;
; :Params:
; sEvent: in, required, type="struct"
; An IDL event structure
;-
pro roi_demo_event, sEvent
widget_control, sEvent.top, GET_UVALUE=oRoiDemo
oRoiDemo->Event, sEvent
end
; Checks ENVI for any ROIs. DIsplays all of the ROIs found in the message
; text box.
; :Keywords:
; PREFIX: in, optional, type="string"
; A string or string array of text to be added to the beginning of the ROI
; message.
pro roi_demo::CheckROIs, $
PREFIX=prefix
compile_opt idl2, logical_predicate
IDLcf$Get, /INCLUDE_VIS_CHILDREN, VIS_LAYERS=oVisLayers
name = []
for i = 0, n_elements(oVisLayers)-1 do begin
if isa(oVisLayers[i], 'IDLcfVisROINative') then begin
void = oVisLayers[i]->AddObserver(self)
oROI = oVIsLayers[i]->GetParameter('ROI')
if obj_valid(oROI) then begin
name = [name, oROI.name]
endif
endfor
if (n_elements(prefix) EQ 0) then prefix = 'ROIs found:'
str = [prefix,(n_elements(name) GT 0) ? name : 'No ROIs found']
widget_control, widget_info(self.tlb, FIND_BY_UNAME='text_message'), SET_VALUE=str
; Creates a dialog for displaying information regarding the ENVI ROIs
pro roi_demo::Dialog
e = envi(/CURRENT)
self.tlb = widget_base(/COLUMN, /FLOATING, GROUP_LEADER=e.widget_id, $
TITLE='ENVI ROI Demo')
xSize = 100
wLabel = widget_label(self.tlb, /ALIGN_LEFT, VALUE='Notification Information')
wText = widget_text(self.tlb, UNAME='text_params', XSIZE=xSize, YSIZE=3)
wLabel = widget_label(self.tlb, /ALIGN_LEFT, VALUE='ROI Information')
wText = widget_text(self.tlb, UNAME='text_message', XSIZE=50, YSIZE=10)
wBase = widget_base(self.tlb, /ALIGN_RIGHT, /ROW)
wButton = widget_button(wBase, UNAME='check_roi', VALUE='Check ROIs')
widget_control, self.tlb, /REALIZE, SET_UVALUE=self
self->CheckROIs
xmanager, 'roi_demo', self.tlb, /NO_BLOCK
; Event handler for the ROI demo's dialog
pro roi_demo::Event, sEvent
case widget_info(sEvent.id, /UNAME) of
'check_roi': self->CheckROIs
else: print, widget_info(sEvent.id, /UNAME)
endcase
; Lifecycle method for initializing the object
; :Returns:
; 1 if the object initializes successfully and 0 otherwise
function roi_demo::Init, $
_REF_EXTRA=refExtra
if (~self->IDLmiObserver::Init(_EXTRA=refextra)) then begin
print, 'Failed to initialize IDLmiObserver'
return, 0
return, 1
; This method is for receiving notifications from the notifiers for which this
; class is an observer.
; 1
; oSubject: in, required, type="objref"
; The ENVI object that is sending the notifications
; strMsg: in, required, type="string"
; The notification string (e.g. SETPROPERTY)
; strArg: in, required, type="string"
; A string containing additional notification information (e.g. HIDE)
function roi_demo::OnNotify, oSubject, strMsg, strArg
oSubject->GetProperty, NAME=name
help, oSubject, OUTPUT=strHelp
widget_control, widget_info(self.tlb, FIND_BY_UNAME='text_params'), $
SET_VALUE=[strHelp, 'STRMSG: '+strMsg, 'STRARG: '+strArg]
str = ''
case strupcase(strMsg) of
'ADDITEMS': begin
str = ['Adding a new ROI','Press Check ROIs when finished']
'REMOVEITEMS': begin
self->CheckROIs, PREFIX=['ROI has been removed','Remaining ROIs:']
'ROI_DEFINITION_CHANGE': begin
str = name+' has been updated'
'SETPROPERTY': begin
case strupcase(strArg) of
'COLOR': begin
oROI = oSubject->GetParameter('ROI')
oROI->GetProperty, COLOR=color
str = name+' color changed to '+strjoin(strtrim(fix(color),2),',')
'HIDE': begin
oSubject->GetProperty, HIDE=hide
str = name+' has been '+(hide ? 'hidden' : 'shown')
else:
else: print, 'MESSAGE: '+strMsg
wText = widget_info(self.tlb, FIND_BY_UNAME='text_message')
widget_control, wText, SET_VALUE=str
; Class structure definition
; :Inherits:
; IDLmiObserver
; :Fields:
; tlb: This widget ID of the dialog's top level base.
pro roi_demo__define
void = {roi_demo $
, inherits IDLmiObserver $
, tlb : 0L $
}
pro roi_demo
if ~isa(e, 'envi') then begin
e = envi()
eView = e->GetView()
file = Filepath('qb_boulder_msi', ROOT_DIR=e.root_dir, SUBDIRECTORY=['data'])
eRaster = e->OpenRaster(file)
eLayer = eView->CreateLayer(eRaster)
file = Filepath('qb_boulder_roi.xml', ROOT_DIR=e.root_dir, SUBDIRECTORY=['data'])
eROI = e->OpenROI(file)
nROI = n_elements(eROI)
eLayerROI = objarr(nROI)
for i = 0, nROI-1 do begin
eLayerROI[i] = eLayer->AddROI(eROI[i])
oROIDemo = obj_new('roi_demo')
oROIDemo->Dialog
Number of views (2865)/Comments (1)
Mobit Solutions
5/31/2016 5:40 AM
I did not understand the program in the middle. I'll go through it again and I'll definitely try this in my seo company.
Sign Up for News & Updates: Stay informed with the latest news, events, technologies and special offers.