Custom Task Example: Compute the Number of Classes

This example uses a custom task in the first step. It determines the number of classes to use for ISODATA classification (in the second step) by adding two user-specified numbers in the first step. Although this is a very basic example, it demonstrates how to perform custom tasks inside of a workflow.

Copy and paste this code into the IDL Editor. Save the file as example_custom_task.pro. Then compile and run the program.

; This is the stylesheet callback routine for Step 2

PRO custom_task_step2_stylesheet, styleSheet, _REF_EXTRA=refExtra

COMPILE_OPT IDL2

 

; Show and hide certain task parameters for ISODATA classification

ENVIWorkflowStep.StyleSheetShowParameters, styleSheet, 'NUMBER_OF_CLASSES'

ENVIWorkflowStep.StyleSheetHideParameters, styleSheet, 'CHANGE_THRESHOLD_PERCENT'

ENVIWorkflowStep.StyleSheetHideParameters, styleSheet, 'ITERATIONS'

 

END

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

; Add the two user-specified numbers in Step 1

PRO custom_task_step1_execute, input_number=inputNumber, add_number=addNumber, $

  output_number=outputNumber

COMPILE_OPT IDL2

 

outputNumber = inputNumber + addNumber

 

END

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

 

; This is the workflow routine

PRO example_custom_task

COMPILE_OPT IDL2

 

; Start the application

e = ENVI()

 

; Create and customize a workflow

workflow = ENVIWorkflow()

workflow.TITLE = 'Custom Task Workflow'

 

; Add a step to compute the number of classes

step1 = ENVIWorkflowStep()

step1.TITLE = 'Compute Number of Classes'

step1.TITLE = 'Custom Task Example'

step1.TIMELINE_TITLE = 'Add Numbers'

step1.Task.AddParameter, IDLParameterUInt($

 NAME='input_number', $

  DISPLAY_NAME='Input Number', $

  DIRECTION='input', $

  DEFAULT=1)

step1.Task.AddParameter, IDLParameterUInt($

  NAME='add_number', $

  DISPLAY_NAME='Number to Add', $

  DIRECTION='input', $

  DEFAULT=1)

step1.Task.AddParameter, IDLParameterUInt($

  NAME='output_number', $

  DIRECTION='output')

step1.CALLBACK_EXECUTE = 'custom_task_step1_execute'

 

; Add a step for ISODATA classification

step2 = ENVIWorkflowStep()

step2.TASK = ENVITask('ISODATAClassification')

step2.TIMELINE_TITLE = 'Classify'

 

; Apply a revised style sheet to Step 2

step2.CALLBACK_APPLY_STYLESHEET = 'custom_task_step2_stylesheet'

 

; Connect workflow steps

workflow.Connect, step1, 'OUTPUT_NUMBER', step2, 'NUMBER_OF_CLASSES'

 

; Display the workflow dialog

envi.UI.CreateWorkflowDialog, workflow

END

Result:

See Also

Customize Workflows