how to use WinProp_WriteBitmapLegend in winprop API?

bin bin lu
bin bin lu New Altair Community Member
edited July 2023 in Community Q&A

hi all,

     i want to output bitmap file with legend of result using winprop api below. But i don't know how to define the parameters ( such as Legend)?

     would anyone give me some tips and example code ?

    thanks very much!

 

       int WinProp_WriteBitmapLegend(WinProp_Result * Result, double MeterPerPixel, char *

      FilenameOutput, WinProp_Legend * Legend)

Tagged:

Answers

  • reinerh
    reinerh
    Altair Employee
    edited July 2023

    Hi,

    this can be done as shown in the example on page 199 of the WinProp API reference guide:

    WinProp_Legend Legend;
    // init
    WinProp_Structure_Init_Legend(&Legend);

    Then WinProp_Legend_Allocate needs to be called with the NrSamplingPoints equal to the number of thresholds to be used in the legende. And before the program end then WinProp_Legend_Free.

    The legende can then be configured using the following code:

    int WinProp_Legend_Configure(
        WinProp_Legend      *Legend,
        double              MinValue,
        double              MaxValue
    )
    {
        int Sample, Position;
        double Value, Step;
      int Palette[LEGEND_PALETTE_MAXIMUM_REGULAR];

      /* Setting the Parameter. */
        Value = MinValue;
        Step = (MaxValue - MinValue) / (double)(Legend->NrSamplingPoints-1);

      /* Definition of the rainbow palette */
      WinProp_Rainbow_Fill(Palette, LEGEND_PALETTE_MAXIMUM_REGULAR);

        for (Sample=0; Sample<Legend->NrSamplingPoints; Sample++)
        {
          /* Assign actual level */
            Legend->SamplingPoints[Sample].Value = Value;

          /* Assign actual color */
          Position = (int)((Value - MinValue) / (MaxValue - MinValue) * (double)LEGEND_PALETTE_MAXIMUM_REGULAR);
            Legend->SamplingPoints[Sample].Color = Palette[Position];

          /* Next threshold */
            Value += Step;
        }

        return(0);
    }

    with

    int WinProp_Rainbow_Fill(
        int                 *Colors,
        int                 Number
    )
    {
        int Loop, Position = 0;
        unsigned char Red, Green, Blue;

      /* To generate the rainbow the following */
      /* color sequence must be set */
        /*
        1.red = 255 ; green = 0 -> 255 ; blue = 0
        2.red = 255 -> 0 ; green = 255 ; blue = 0
        3.red = 0 ; green = 255 ; blue = 0 -> 255
        4.red = 0 ; green = 255 -> 0 ; blue = 255
        5.red = 0 -> 255 ; green = 0 ; blue = 255
        6.red = 255 ; green = 0 ; blue = 255 -> 0
        */

        /* Step 1 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = 255;
            Green = Loop;
            Blue = 0;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        /* Step 2 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = 255 - Loop;
            Green = 255;
            Blue = 0;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        /* Step 3 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = 0;
            Green = 255;
            Blue = Loop;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        /* Step 4 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = 0;
            Green = 255 - Loop;
            Blue = Loop;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        /* Step 5 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = Loop;
            Green = 0;
            Blue = 255;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        /* Step 6 */
        for (Loop=0; Loop<256; Loop++)
        {
            Red = 255;
            Green = 0;
            Blue = 255 - Loop;

            Colors[Number - Position - 1] = RGB(Red, Green, Blue);
            Position++;
        }

        return(0);
    }