Hexagon Geospatial
MENU

Developers Knowledge Base

Read articles and post questions in this comprehensive developer community and support forum.
Showing results for 
Search instead for 
Do you mean 

Using a Color Ramp in an operator

by Technical Evangelist on ‎06-20-2016 01:50 PM (698 Views)

Question

What is the best way for my operator to take in and apply a color ramp to raster data?

Answer

An operator's use of a color ramp / look-up table is simple in the simple cases, but in order to be robust, it needs to consider something called a Bin Function. A Bin Function describes how to take a pixel value and map it to a row in a table. A Bin Function of type “direct” represents the simple cases (the pixel value represents the row in the table). But for large integer types and floating point types, a direct Bin Function usually isn’t possible or desired.

 

So particularly in cases where DEMs are involved (which can be floating point), an oerator needs to be very deliberate in its approach. A general rule of thumb for Operator developers is to hide the use of a Bin Function as much as possible from model developers (because it’s an advanced topic that often doesn’t need to be delved into).

 

So in order to use a color-ramp / look-up table, an operator should accept an input parameter of the IMAGINE.Table data type. There are several operators (Color Ramp Input, Create Color Ramp) that deliver this data type. An IMAGINE.Table may carry a Bin Function with it and the operator needs to check for this and apply it.

 

  1. The data type that the port should support is IMAGINE.Table.
  2. The operator will have to verify that the table is a color table.
  3. TablePtr colorTable = GetPort(L"Colorization")->GetDataPtr<TableData>(Port::ReturnNullIfEmpty);
    if (colorTable)
    {
         if (!colorTable->IsColor())
         {
               SetErrorMessage(L"Input table is not a color table.");
         }
  4. The operator should get the Bin Function from the table and, if present, use it.  The Apply Color Table operator uses the Bin Function if it's there.
  5. binFunc = BaseDataStackUtils::GetBinFunctionFromTable(colorTable);
    T inVal = *srcRow++;
    if (binFunc)
    {
         long index = edsc_BinFunctionApply(binFunc, inVal, err);
         EXCEPTION_CHECK(err);
         inVal = (T)index;
    }
    if (inVal >= tableSize)
         inVal = tableSize - 1;
    if (inVal < 0)
         inVal = 0;
    long index = (long)inVal;


Note that the pixel values that have no mapping into the table (whether or not the Bin Function is present) are clamped to the first and last row. Whether this is the proper behavior depends on the particular context. In some cases, it may be desirable to set the corresponding output pixel to NODATA.

 

 

Overview
Contributors