跳转至

ENVI 扩展:从 ENVI ROI 获取通知

原文链接: https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/envi-extensions-getting-notifications-from-envi-rois

20321 对此文评分:

3.3

ENVI 扩展:从 ENVI ROI 获取通知

匿名 2016年2月25日 星期四

我最近的一个项目需要一个 ENVI 扩展来响应在 ENVI 图层管理器中进行的 ROI 更改。幸运的是,ENVI 提供了一种机制,允许对象实现此功能。首先,必须将该对象添加到每个 ROI 图层的观察者列表中。以下命令提供了对这些图层的访问:

IDLcf$Get , /INCLUDE_VIS_CHILDREN, VIS_LAYERS=oVisLayers

变量 oVisLayers 将包含 ENVI 显示中所有可见的图层。要仅获取 ROI,可以遍历其内容,寻找任何 IDLcfVisROINative 的实例。当找到一个时,可以使用以下命令将该对象添加到该 ROI 图层的观察者列表中:

void = oVisLayers[i]->AddObserver(self)

现在对象已添加到观察者列表中,必须添加一个 OnNotify 方法。来自 ROI 图层的任何通知都将发送到此方法。

functionmy_class ::OnNotify, oSubject, strMsg, strArg

输入参数如下:

  • oSubject – 发送通知的 ENVI 对象的引用
  • strMsg – 包含通知名称的字符串(例如 SETPROPERTY)
  • strArg – 包含附加通知信息的字符串(例如 HIDE)

以下是一个独立的示例,演示如何设置一个对象以接收并处理来自 ENVI 图层管理器中 ROI 的通知:

;##############################################################################

; 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**

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

**end**

;------------------------------------------------------------------------------

;+

; Creates a dialog for displaying information regarding the ENVI
ROIs

;-

**pro** **roi\_demo**::Dialog

  **compile\_opt** idl2, logical\_predicate

  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

**end**

;------------------------------------------------------------------------------

;+

; Event handler for the ROI demo's dialog

;

; :Params:

;   sEvent: in, required, type="struct"

;     An IDL event structure

;-

**pro** **roi\_demo**::Event, sEvent

  **compile\_opt** idl2, logical\_predicate

  **case** **widget\_info**(sEvent.**id**, /UNAME) **of**

    'check\_roi': self->**CheckROIs**

    **else**: **print**, **widget\_info**(sEvent.*id*, /UNAME)

  **endcase**

**end**

;------------------------------------------------------------------------------

;+

; Lifecycle method for initializing the object

;

; :Returns:

;   1 if the object initializes successfully and 0 otherwise

;-

**function** **roi\_demo**::Init, $

  \_REF\_EXTRA=refExtra

  **compile\_opt** idl2, logical\_predicate

  **if** (~self->**IDLmiObserver::Init**(\_EXTRA=refextra)) **then** **begin**

    **print**, 'Failed to initialize IDLmiObserver'

    **return**, **0**

  **endif**

  **return**, **1**

**end**

;------------------------------------------------------------------------------

;+

; This method is for receiving notifications from the notifiers
for which this

; class is an observer.

;

; :Returns:

;   1

;

; :Params:

;   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

  **compile\_opt** idl2, logical\_predicate

  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']

    **end**

    'REMOVEITEMS': **begin**

      self->**CheckROIs**, PREFIX=['ROI has been removed','Remaining ROIs:']

      **return**, **1**

    **end**

    'ROI\_DEFINITION\_CHANGE': **begin**

      str = name+' has been updated'

    **end**

    '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**),',')

        **end**

        'HIDE': **begin**

          oSubject->**GetProperty**, HIDE=hide

          str = name+' has been '+(hide ? 'hidden' : 'shown')

        **end**

        **else**:

      **endcase**

    **end**

    **else**: **print**, 'MESSAGE: '+strMsg

  **endcase**

  wText = **widget\_info**(self.*tlb*, FIND\_BY\_UNAME='text\_message')

  **widget\_control**, **wText**, SET\_VALUE=str

  **return**, **1**

**end**

;------------------------------------------------------------------------------

;+

; Class structure definition

;

; :Inherits:

;   IDLmiObserver

;  

; :Fields:

;   tlb: This widget ID of the dialog's top level base.

;-

**pro** **roi\_demo\_\_define**

  **compile\_opt** idl2, logical\_predicate

  void = {**roi\_demo**           $

   

    , **inherits** **IDLmiObserver** $

    , *tlb*  : **0L**              $

   

      }

**end**

;------------------------------------------------------------------------------

;+

;-

**pro** **roi\_demo**

  **compile\_opt** idl2, logical\_predicate

  e = **envi**(/CURRENT)

  **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])

    **endfor**

  **endif**

  oROIDemo = **obj\_new**('roi\_demo')

  oROIDemo->**Dialog**

**end**

使用 Jagwire 组织数据以节省时间和精力 关于从影像识别植被物种的真相