The POLYFILLV function returns a vector containing the subscripts of the array elements contained inside a polygon defined by vectors.

The *X* and *Y* parameters are vectors that contain the subscripts of the vertices that define the polygon in the coordinate system of the two-dimensional *S*_{x} by *S*_{y} array. The *S*_{x} and *S*_{y} parameters define the number of columns and rows in the array enclosing the polygon. At least three points must be specified, and all points should lie within the limits: 0 â‰¤ X_{i} < S_{x} and 0 â‰¤ Y_{i} < S_{y} for all *i*.

As with the POLYFILL procedure, the polygon is defined by connecting each point with its successor and the last point with the first. This function is useful for defining, analyzing, and displaying regions of interest within a two-dimensional array.

### Algorithm

The scan-line coordinate system is used, as defined by Rogers in *Procedural Elements for Computer Graphics*, McGraw-Hill, 1985, page 71. In this system, the scan lines are considered to pass through the center of each row of pixels. Pixels are activated if the center of the pixel is to the right of the intersection of the scan line and the polygon edge within the interval. This implies that for a given set of vertices, some of the vertices themselves may not be included in the returned result.

For example, imagine a square polygon, extending from pixels 2 to 4 in a 6x6 array:

subscripts = POLYFILLV( [2,4,4,2,2], [4,4,2,2,4], 6, 6 )

filled = BYTARR(6, 6)

` filled[subscripts] = 1`

` print, filled`

IDL prints:

0 0 0 0 0 0

0 0 0 0 0 0

0 0 1 1 0 0

0 0 1 1 0 0

0 0 0 0 0 0

0 0 0 0 0 0

Note that only points 2:3 in each dimension are included in the polygon, where you might have expected pixels 2:4. The result can be verified by checking the area of the polygon. Here, the original area is 4 pixels, and 4 indices are returned in the subscripts from POLYFILLV.

## Examples

To determine the mean and standard deviation of the elements within a triangular region defined by the vertices at pixel coordinates (100, 100), (200, 300), and (300, 100), inside a 512 x 512 array called DATA, enter the commands:

`; Get the subscripts of the elements inside the triangle:`

P = DATA[POLYFILLV([100,200,300], [100,300,100], 512, 512)]

`; Use the STDEV function to obtain the mean and standard deviation `

`; of the selected elements:`

`STD = STDEV(P,MEAN)`

## Syntax

*Result* = POLYFILLV( *X*,* Y*,* S*_{x},* S*_{y}[, *Run_Length*] )

## Return Value

Returns a vector containing the one-dimensional subscripts of the array elements contained inside a polygon defined by vectors *X* and *Y*. These subscripts will be LONG64 values if the dimensions of the input array (*S _{x}* *

*S*) warrant that size for proper addressing. If no points are contained within the polygon, a -1 is returned, and an informational message is printed.

_{y}## Arguments

### X

A vector containing the X subscripts of the vertices that define the polygon.

### Y

A vector containing the Y subscripts of the vertices that define the polygon.

### S_{x}

The number of columns in the array surrounding the polygon.

### S_{y}

The number of rows in the array surrounding the polygon.

### Run_Length

Set this optional parameter to a nonzero value to make POLYFILLV return a vector of run lengths, rather than subscripts. For large polygons, a considerable savings in space results. When run-length encoded, each element with an even subscript result contains the length of the run, and the following element contains the starting index of the run.

## Version History

Original |
Introduced |

## See Also