Admin Production ni-theme
Current Publication

PlotIntensity

LabWindows/CVI

PlotIntensity

int PlotIntensity (int panelHandle, int controlID, void *zArray, size_t numberOfXPoints, size_t numberOfYPoints, int zDataType, ColorMapEntry colorMapArray[], int hiColor, size_t numberOfColors, int interpColors, int interpPixels);

Purpose

Draws a solid rectangular plot in a graph control. If you want to apply scaling factors and offsets to the data values, refer to PlotScaledIntensity.

Note Note  A new plot is created each time this function is called. You must call the DeleteGraphPlot function to dispose of each plot.

The plot consists of pixels whose colors correspond to the magnitude of data values in a two-dimensional array and whose coordinates correspond to the locations of the same data values in the array. For instance, the pixel associated with zArray[2][3] is located at {x=3, y=2}.

The lower left corner of the plot area is at {0,0}.

The upper right corner of the plot area is at {numXpts1, numYpts1}, where, numXpts is the number of x points and numYpts is the number of y points.

Example Code

The following example code demonstrates how to use this function to plot an intensity graph. interpColors is zero. Therefore, if a zArray data value does not match a data value in one of the ColorMapEntry structures exactly, LabWindows/CVI plots the color associated with the next higher ColorMapEntry data value. In this example, LabWindows/CVI plots the first two zArray values as white, the next two data values as light gray, the next two data values as dark gray, and the last two data values as black. The hiColor parameter is ignored in this case, because the zArray data does not contain any value greater than the highest value in the ColorMapEntry table.

int CVICALLBACK PlotIntensityGraph (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)

{

int zArray[8] = {0, 1, 2, 3, 4, 5, 6, 7};

ColorMapEntry colors[4];

colors[0].color = VAL_WHITE;

colors[0].dataValue.valInt = 1;

colors[1].color = VAL_LT_GRAY;

colors[1].dataValue.valInt = 3;

colors[2].color = VAL_DK_GRAY;

colors[2].dataValue.valInt = 5;

colors[3].color = VAL_BLACK;

colors[3].dataValue.valInt = 7;

switch (event)

{

case EVENT_COMMIT:

PlotIntensity (panelHandle, PANEL_GRAPH, zArray, 2, 4, VAL_INTEGER, colors, VAL_BLACK, 4, 0, 0);

break;

}

return 0;

}

Supported Controls

You can use PlotIntensity with graph controls.

Parameters

Input
Name Type Description
panelHandle int Specifier for a particular panel that is currently in memory. You can obtain this handle from functions such as LoadPanel and NewPanel.
controlID int The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by functions such as NewCtrl and DuplicateCtrl.
zArray void * Array that contains the data values to convert to colors.

The data type must be of the type you specify in zDataType.

The locations at which the colors appear on the graph depend on the location of the data values in zArray. zArray must be a two-dimensional array of the following form:

Array[numberOfYPoints][numberOfXPoints]

Each element of the array is associated with a pixel on the graph. The pixel associated with element zArray[y][x] is located at {x, y} on the graph.
numberOfXPoints size_t Number of points to display along the x-axis in each row.

This value must be less than or equal to INT_MAX.
numberOfYPoints size_t Number of points to display along the y-axis in each column.

This value must be less than or equal to INT_MAX.
zDataType int The data type of the elements in zArray, as well as the data type of the color map values.

The following table lists the valid data types.

VAL_CHAR A single byte character.
VAL_SHORT_INTEGER A 2 byte integer.
VAL_INTEGER A 4 byte integer.
VAL_FLOAT A 4 byte floating point value.
VAL_DOUBLE An 8 byte floating point value.
VAL_64BIT_INTEGER An 8 byte integer.
VAL_UNSIGNED_SHORT_INTEGER An unsigned 2 byte integer.
VAL_UNSIGNED_INTEGER An unsigned 4 byte integer.
VAL_UNSIGNED_CHAR An unsigned single byte character.
VAL_UNSIGNED_64BIT_INTEGER An unsigned 8 byte integer.
VAL_SIZE_T An unsigned 4 byte integer (32-bit applications).
An unsigned 8 byte integer (64-bit applications).
VAL_SSIZE_T A 4 byte integer (32-bit applications).
An 8 byte integer (64-bit applications).
VAL_PTRDIFF_T A 4 byte integer (32-bit applications).
An 8 byte integer (64-bit applications).
VAL_UINTPTR_T An unsigned 4 byte integer (32-bit applications).
An unsigned 8 byte integer (64-bit applications).
VAL_INTPTR_T A 4 byte integer (32-bit applications).
An 8 byte integer (64-bit applications).
colorMapArray ColorMapEntry[] Array of ColorMapEntry structures.

colorMapArray contains up to 255 ColorMapEntry structures that are defined as follows:

typedef struct
{

union
{

char valChar;
int valInt;
__int64 valInt64;
short valShort;
float valFloat;
double valDouble;
unsigned char valUChar;
unsigned long valULong;
unsigned __int64 valUInt64;
unsigned short valUShort;

} dataValue;
int color;

} ColorMapEntry;



colorMapArray defines how to translate data values in zArray into color values. If a data value matches exactly to a data value in one of the ColorMapEntry structures, the function converts it to the corresponding color. Otherwise, the following rules apply:

  • If interpColors is zero, the color associated with the next higher data value is used.
  • If interpColors is nonzero, the color is calculated using a weighted mean of the colors associated with the color map data values immediately above and below the zArray value.

If there is no higher value, the function uses the color specified in hiColor.

The colorMapArray entries do not need to be in sorted order.
hiColor int RGB value to which to translate zArray values that are higher than the highest data value in colorMapArray.
numberOfColors size_t Number of entries in colorMapArray. numberOfColors must be less than or equal to 255.

If interpColors is nonzero, numberOfColors must be greater than or equal to two.
interpColors int Indicates how to assign colors to zArray data values that do not exactly match the data values in the colorMapArray.

If interpColors is zero, the data value is assigned the color associated with the next higher color map data value.

If interpColors is nonzero, the color is calculated using a weighted mean of the colors associated with the color map data values immediately above and below the zArray value.

Regardless of the value of interpColors, the following rules apply:

  • Data values below the lowest color map data value are assigned the color of the lowest color map data value.
  • Data values above the highest color map data value are assigned the value of the hiColor parameter.
interpPixels int Indicates how to color pixels between the pixels assigned to the zArray values.

If interpPixels is zero, an unassigned pixel is given the same color as the closest assigned pixel.

If interpPixels is nonzero, an unassigned pixel is first given a data value using a weighted mean of the data values associated with the four closest assigned pixels. Then the color is calculated using the colorMapArray.

Performance Considerations

If interpPixels is zero, the performance degrades as the number of data points in zArray increases.

If interpPixels is nonzero, the performance degrades as total number of pixels in the plot area increases.

Return Value

Name Type Description
plotHandle int The handle of the new plot that you can use in subsequent function calls to reference the plot.

If the handle is positive, the new plot was successfully added to the graph. Negative values indicate that an error occurred.

Note  If ATTR_DATA_MODE is set to VAL_DISCARD, the function returns 0.

Additional Information

Library: User Interface Library

Include file: userint.h

LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later

Examples

Refer to the following examples that use the PlotIntensity function:

  • apps\mandelbrot\mandel.cws

    Open example
  • apps\oglscxi\oglscxi.cws

    Open example
  • userint\graphlegend.cws

    Open example
  • userint\gridview.cws

    Open example
  • userint\custctrl\colorpicker\colorpickerdemo.cws

    Open example
  • userint\custctrl\cviogl\oglsim.cws

    Open example