Instead of using ENVITaskFromProcedure as the base class for your custom tasks, you can write a custom base class. Just like ENVITaskFromProcedure, a custom base class maps the parameters from your IDL procedure to an ENVITask. A custom base class is helpful in the following situations:

  • You are writing several custom tasks that have the same parameter settings. For example, you may have a set of supervised classification tasks that will have the same MEAN value for training data statistics.
  • You want the same application behavior in all of your custom tasks. For example, you may always want data processing results to appear in the Data Manager after task exection. Or, you may want to generate pyramids during task execution instead of waiting until the results display.
  • You want to hide certain parameters from the end user of your custom task. For example, INTERLEAVE is typically a required parameter when opening input rasters, but you don't want end users to always specify the interleave value when selecting input rasters. You can set the default value of INTERLEAVE, then hide it so that end users don't need to specify it.

Example: Define a Base Class that Inherits from ENVITaskFromProcedure


This example shows how to write a custom base class that inherits from ENVITaskFromProcedure. The base class will contain its own PreExecute and PostExecute methods that provide additional functionality. In the task template, base_class will refer to the new base class instead of ENVITaskFromProcedure. Follow the steps below.

Tip: Copies of these files are available in the ENVI installation path under the \examples\tasks\baseclassexample folder. Rather than copy and paste the contents from each step into new files, you can copy the files from the ENVI installation path into the locations referenced below. If you do not have write permissions to copy files into the ENVI installation path, see Deploy Tasks for other options.

  1. Refer to Image Threshold Procedure. This topic shows an IDL program that takes an input ENVIRaster, runs the IDL IMAGE_THRESHOLD routine, and creates a thresholded output raster. Copy its contents and save it to a file named ENVIImageThresholdExample.pro in the ENVIxx\custom_code directory of the ENVI installation path.
  2. Refer to Image Threshold Class. This topic shows an IDL class definition that inherits from ENVITaskFromProcedure and adds functionality to the PreExecute and PostExecute methods. Copy its contents and save it to a file named ImageThresholdExample__Define.pro in the ENVIxx\custom_code directory of the ENVI installation path.
  3. Refer to Max Entropy Threshold Task. This topic shows a task definition that uses the code from Steps 1 and 2. Copy its contents and save it to a file named MaxEntropyThresholdExample.task in the ENVIxx\custom_code directory of the ENVI installation path.
  4. In the task template, notice that the base_class key is set to the Image Threshold class from Step 2. It also contains two hidden parameters: MAXENTROPY and INTERLEAVE. The IMAGE_THRESHOLD routine has many keywords for different thresholds. Instead of creating one task with all the different thresholds, you can create a separate task for each.

    By having a hidden MAXENTROPY parameter, the MAXENTROPY keyword is set to 1 and is passed to ENVIImageThresholdExample.pro. INTERLEAVE is a required keyword to IMAGE_THRESHOLD; it is set to 0, 1, or 2.

    Since an ENVIRaster is required input, you can translate the ENVIRaster interleave of BIP, BIL, and BSQ to the required 0, 1, or 2 in the task definition. In the PreExecute method, set INTERLEAVE to the interleave of the input ENVIRaster.

  5. Refer to Mean Threshold Task. This topic shows a task definition that is similar to the Max Entropy Threshold task, except that the MEAN threshold is set to 1. So when the task runs, the MEAN keyword is already set for IMAGE_THRESHOLD. Copy its contents and save it to a file named MeanThresholdExample.task in the ENVIxx\custom_code directory of the ENVI installation path.
  6. Refer to Min Error Threshold Task. This topic shows a task definition that is similar to the other two task definitions, except that the MINERROR threshold is set to 1. So when the task runs, the MINERROR keyword is already set for IMAGE_THRESHOLD. Copy its contents and save it to a file named MinErrorThresholdExample.task in the ENVIxx\custom_code directory of the ENVI installation path.
  7. Refer to Image Threshold Task Execution. This topic shows an IDL program that runs the three image threshold tasks that you created. Copy its contents and save it to a file named RunImageThresholdExampleTask.pro in your IDL workspace.
  8. Compile and execute RunImageThresholdExampleTask.pro to run the custom tasks. ENVI will display the resulting thresholded rasters.