This is an old revision of the document!


Creating an operator

TerraAIDA project aims to build InterIMAGE operators using the TerraLib library following the GNU LGLP license model. More information at http://www.dpi.inpe.br/terraaida/.

This page will present an example of how to create your own InterIMAGE operator, using TerraLib.

After created, your operator must have two files, to be inserted into InterIMAGE:

  • The binary, which will perform the implemented operation,
  • The .op file descriptor, describing the parameters, understandable by InterIMAGE GUI.

In this page we describe how to create the source-code of the operator. For information about how to define your .op file descriptor, read the Section “3.1. Operator Description File”, in the System Overview Operation Guide.

The structure of files should follow this example in order to run properly.

The operator main file will call the operator function, which checks the parameters and produces the output. The operator function header can also communicate with InterIMAGE GUI in order to be called directly. Here we create a simple operator, which gets an image by input, and outputs the regions according a certain threshold defined by the user.

Operator Main File

#include <execTAThreshold.hpp>
#include <OpSupportFunctions.hpp>
 
#include <iostream>
 
int main( int argc, char ** argv )
{
  // if executed with no parameters
  if( argc == 1 )
  {
    std::cout << std::endl << "TerraAIDA threshold operator - Version " + 
      OpSupportFunctions::getTAVersion() << std::endl;
    return EXIT_SUCCESS;
  }
 
  // if executed with parameters
  return TerraAIDA::execTAThreshold( argc, argv );
}

Operator Function Header

#ifndef TAEXECTHRESHOLD_HPP
  #define TAEXECTHRESHOLD_HPP
 
  namespace TerraAIDA
  {
    /**
     * @brief TerraAIDA threshold operator function.
     * @param argc Arguments count.
     * @param argv Arguments strings.
     * @return EXIT_FAILURE or EXIT_SUCCESS
     */  
    int execTAThreshold( int argc, char ** argv );
  }
 
#endif  

Operator Function Implementation

#include "execTAThreshold.hpp"
#include "OpSupportFunctions.hpp"
 
#include <TePDIUtils.hpp>
#include <TePDIRaster2Vector.hpp>
 
namespace TerraAIDA
{
  int execTAThreshold( int argc, char ** argv )
  {
    try 
    {
      // read input
      // process input
      // generate output
    }
    catch( const TeException& e ) {
      TEAGN_LOGERR( e.message() )
      return EXIT_FAILURE;
    }    
    catch( ... ) {
      TEAGN_LOGERR( "Unhandled exception" )
      return EXIT_FAILURE;
    }  
 
    TEAGN_LOGMSG( "Thresholding finished" )
    return EXIT_SUCCESS;
  }
 
}

Reading Input

      /* Extracting system default parameters */
 
      int param_index = 1;
 
      const double geoWest = atof( argv[ param_index ] );
      ++param_index;
 
      const double geoNorth = atof( argv[ param_index ] );
      ++param_index;
 
      const double geoEast = atof( argv[ param_index ] );
      ++param_index;
 
      const double geoSouth = atof( argv[ param_index ] );
      ++param_index;
 
      const std::string output = argv[ param_index ];
      ++param_index;
 
      const std::string class_str = argv[ param_index ];
      ++param_index;
 
      const std::string tmpdir = argv[ param_index ];
      ++param_index;
 
      bool use_mask = true;
      const std::string mask_file = argv[ param_index ];
      if( mask_file.empty() ) use_mask = false;
      ++param_index;
 
      /* Extracting user parameters */
 
      const std::string image_name = argv[ param_index ];
      ++param_index;
      TEAGN_TRUE_OR_THROW( image_name.find( ";" ) ==
        image_name.npos, "Only one input image file must be used" )    
 
      const int image_channel = atoi( argv[ param_index ] );    
      ++param_index;
 
      const double treshold_min = atof( argv[ param_index ] );
      ++param_index;
 
      const double treshold_max = atof( argv[ param_index ] );
      ++param_index;
 
      const double node_weight = atof( argv[ param_index ] );
      ++param_index;       
 

Processing Input

 

Generating the Output

      /* Generating the output labeled image */
      TEAGN_TRUE_OR_THROW( OpSupportFunctions::saveLabeledImageFile(
        output_image_file_name, thres_raster_filtered_ptr, 0 ),
        "Error saving label image" )
 
      /* Generating output polygons file */
      TEAGN_TRUE_OR_THROW( OpSupportFunctions::createRegionsDescFile( 
        output, regions_data_vector, thres_raster_filtered_ptr->params(), 
        node_weight,
        geoWest, geoNorth, geoEast, geoSouth ), 
        "Unable to export polygons file" );

Navigation