home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Rapid Contour Plots By Bilinear Patch
-
-
- In this technique, the points of the original data array are viewed as
- being samples of a function that is continuous, with piecewise
- continuous partial derivatives. This function is presumed to be
- bilinear within the squares delineated by the data points. In order
- to prepare the contour plot of the entire region, we merely prepare a
- contour plot of each square "patch" delineated by four adjacent data
- points. There is one potential problem with this method, and that is
- if a contour value is exactly equal to one of the data values (one of
- the values exactly on the corner of a patch), then the plot becomes
- ill-conditioned. In the software example provided, this is readily
- prevented. The data values take on only integer values, while the
- contour levels are floating point. We simply prevent any contour
- value from taking on an exact integer value by adding a small number
- (constant called epsilon) if we determine that the contour value is an
- exact integer.
-
- Once this conditioning problem is resolved, it may readily be seen
- that within a single patch, for a specified contour level, exactly
- three possibilities exist: no contour line crosses the patch,
- determined if the contour level is either less than the minimum of the
- four corner values or greater than the maximum of the corner values;
- one contour line crosses the patch; or two contour lines cross the
- patch. In the case where one contour line crosses the patch, the
- bilinear equation is solved for the endpoints of the contour line and
- the line is plotted. In the case where two contour lines cross the
- patch, we determine the four endpoints, and then must decide which
- pairs of endpoints to match to draw the appropriate contour lines.
- Define the bilinear coefficients for the patch in a coordinate system
- local to the patch, so that the x value ranges from 0 to 1 and the y
- value ranges from 0 to 1, and let the bilinear equation be:
-
- value(x,y) = ax + by + cxy +d.
-
- If we now attempt to parametrize the contour line in x in terms of y
- we find:
-
- x = (value - contour level - by - d)/(a + cy).
-
- We then see, that because of the nature of the local coordinate
- system, one of the contour lines must have the y value of both of its
- endpoints greater than -a/c, and the other contour line must have both
- of its endpoints less than -a/c. (It should be noted that because of
- the non-integral nature of the contour level, we cannot have two
- contour lines in a patch when c=0). This means that if we simply sort
- the four endpoints in increasing value of their y-values, that the two
- endpoints with the lowest y-values form a pair for one contour line
- and the two endpoints with the highest y-values form a pair for the
- other contour line.
-
- In the software example provided, contour lines are approximated by
- drawing straight lines from one edge of the bilinear patch to the
- other. In cases where the number of data points are large relative to
- the screen pixel density (say 20 x 20 data points for an EGA display),
- this is adequate for reasonable contour plots. If the data are
-
-
-
-
-
-
-
-
-
- sparse, it may be desirable to plot the contour line more accurately
- within the patch, using the parametrized equation above.
-
- The software example provided consists of three modules and one main
- program. The first module is c_defs.pas and contains the definitions
- used for the contour plotting software, the pointers to the data array
- and the contour level array, and a procedure for allocating memory to
- these arrays. The data array is called data_array_pointer, which
- points to longint data points, via: data=data_array_pointer^[x]^[y],
- with 0<=x<max_x_size and 0<=y<max_y_size. The contour level array
- points to type float (currently set to be single for speed with
- coprocessors), and is accessed via: contour level = contours^[i],
- with 0<=i<max_contours. These data arrays are allocated via a call to
- init_array.
-
- The second module is video.pas and contains the routines necessary for
- manipulating the display. These procedures are: init_graphics, which
- loads the BGI driver for the graphics display (this procedure requires
- that the Borland BGI driver file for the display be in the default
- directory); close_graphics, which returns the display to text mode;
- and make_line, which plots a single contour line through a single
- patch. It should be noted, that as written make_line takes as an
- argument the contour number. The color of the contour line is
- specified by this contour number, so that on EGA and VGA displays, the
- contour plot is color-coded to make it easier to interpret.
-
- The third module is contour.pas and contains the routines necessary
- for contour plotting. The only procedure available for external
- calling is contour_plot, which performs the entire plot function.
-
- The test program, test.pas, is a skeleton of a general user program
- employing the contour plot modules. It performs the operations
- minimally necessary for operation. First, it calls init_array to
- allocate storage. Then, it fills the data array. In this example,
- the data array consists of a sum of two two-dimensional Gaussians plus
- noise. The contour level array is then filled with values (which need
- not be in any particular order). Init_graphics is called to set the
- display to graphics mode, contour_plot is called to perform the plot,
- and finally close_graphics is called to return the display to text
- mode.
-
- The test package is compiled using the Borland command-line compiler,
- version 5.0, by: tpc /B test.pas. All modules internally use
- compiler options $N+ to compile with IEEE floating point and $E+ to
- include the emulator, so that the test program will exhibit identical
- behavior whether a coprocessor is present or not (except for speed).
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-