GR Reference¶

Defines

DLLEXPORT
GR_PROJECTION_DEFAULT
GR_PROJECTION_ORTHOGRAPHIC
GR_PROJECTION_PERSPECTIVE
GR_VOLUME_WITHOUT_BORDER
GR_VOLUME_WITH_BORDER
GR_VOLUME_EMISSION
GR_VOLUME_ABSORPTION
GR_VOLUME_MIP

Functions

void gr_initgr(void)
void gr_opengks(void)
void gr_closegks(void)
void gr_inqdspsize(double*, double*, int*, int*)

Get the current display size.

Depending on the current workstation type, the current display might be the primary screen (e.g. when using gksqt or GKSTerm) or a purely virtual display (e.g. when using Cairo). When a high DPI screen is used as the current display, width and height will be in logical pixels.

Parameters
• [out] mwidth: Display width in meters

• [out] mheight: Display height in meters

• [out] width: Display width in pixels

• [out] height: Display height in pixels

void gr_openws(int, char*, int)

Open a graphical workstation.

Available workstation types:

 Type Description 5 Workstation Independent Segment Storage 41 Windows GDI 61 - 64 PostScript (b/w, color) 101, 102 Portable Document Format (plain, compressed) 210 - 213 X Windows 214 Sun Raster file (RF) 215, 218 Graphics Interchange Format (GIF87, GIF89) 216 Motif User Interface Language (UIL) 320 Windows Bitmap (BMP) 321 JPEG image file 322 Portable Network Graphics file (PNG) 323 Tagged Image File Format (TIFF) 371 Gtk 380 wxWidgets 381 Qt4 382 Scaleable Vector Graphics (SVG) 390 Windows Metafile 400 Quartz 410 Socket driver 415 0MQ driver 420 OpenGL

Parameters
• [in] workstation_id: a workstation identifier

• [in] connection: a connection identifier

• [in] type: the desired workstation type

void gr_closews(int)

Close the specified workstation.

Parameters
• [in] workstation_id: a workstation identifier

void gr_activatews(int)

Activate the specified workstation.

Parameters
• [in] workstation_id: a workstation identifier

void gr_deactivatews(int)

Deactivate the specified workstation.

Parameters
• [in] workstation_id: a workstation identifier

void gr_configurews(void)

Configure the specified workstation.

void gr_clearws(void)
void gr_updatews(void)
void gr_polyline(int, double*, double*)

Draw a polyline using the current line attributes, starting from the first data point and ending at the last data point.

The values for

x and y are in world coordinates. The attributes that control the appearance of a polyline are linetype, linewidth and color index.
Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

void gr_polymarker(int, double*, double*)

Draw marker symbols centered at the given data points.

The values for

x and y are in world coordinates. The attributes that control the appearance of a polymarker are marker type, marker size scale factor and color index.
Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

void gr_text(double, double, char*)

Draw a text at position x, y using the current text attributes.

The values for

x and y are in normalized device coordinates. The attributes that control the appearance of text are text font and precision, character expansion factor, character spacing, text color index, character height, character up vector, text path and text alignment.
Parameters
• [in] x: The X coordinate of the starting position of the text string

• [in] y: The Y coordinate of the starting position of the text string

• [in] string: The text to be drawn

void gr_inqtext(double, double, char*, double*, double*)
void gr_fillarea(int, double*, double*)

Allows you to specify a polygonal shape of an area to be filled.

The attributes that control the appearance of fill areas are fill area interior style, fill area style index and fill area color index.

Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

void gr_cellarray(double, double, double, double, int, int, int, int, int, int, int*)

Display rasterlike images in a device-independent manner. The cell array function partitions a rectangle given by two corner points into DIMX X DIMY cells, each of them colored individually by the corresponding color index of the given cell array.

The values for

xmin, xmax, ymin and ymax are in world coordinates.
Parameters
• [in] xmin: X coordinate of the lower left point of the rectangle

• [in] xmax: X coordinate of the upper right point of the rectangle

• [in] ymin: Y coordinate of the lower left point of the rectangle

• [in] ymax: Y coordinate of the upper right point of the rectangle

• [in] dimx: X dimension of the color index array

• [in] dimy: Y dimension of the color index array

• [in] scol: number of leading columns in the color index array

• [in] srow: number of leading rows in the color index array

• [in] ncol: total number of columns in the color index array

• [in] nrow: total number of rows in the color index array

• [in] color: color index array

void gr_nonuniformcellarray(double*, double*, int, int, int, int, int, int, int*)

Display a two dimensional color index array with nonuniform cell sizes.

The values for

x and y are in world coordinates.
Parameters
• [in] x: X coordinates of the cell edges

• [in] y: Y coordinates of the cell edges

• [in] dimx: actual X dimension of the color index array in the memory

• [in] dimy: actual Y dimension of the color index array in the memory

• [in] scol: 1-based starting column of color index and x array

• [in] srow: 1-based starting row of color index and y array

• [in] ncol: number of columns displayed

• [in] nrow: number of rows displayed

• [in] color: color index array

If dimx and dimy are positive x must contain dimx+1 elements and y must contain dimy+1 elements. The elements i and i+1 are respectively the edges of the i-th cell in X and Y direction.

If dimx and dimy are negative x must contain -dimx elements and y must contain -dimy elements. The i-th element is the center of the i-th cell, and the first and last elements will also be the edges of the outer cells.

To draw all cells of the color index array use:

 gr_nonuniformcellarray(x, y, dimx, dimy, 1, 1, dimx, dimy, color)


scol and srow can be used to specify a (1-based) starting column and row in the color, x and y array. dimx and dimy specify the actual dimension of the arrays in the memory whereof ncol and nrow values are displayed.

void gr_polarcellarray(double, double, double, double, double, double, int, int, int, int, int, int, int*)

Display a two dimensional color index array mapped to a disk using polar coordinates.

The two dimensional color index array is mapped to the resulting image by interpreting the X-axis of the array as the angle and the Y-axis as the radius. The center point of the resulting disk is located at

x_org, y_org and the radius of the disk is rmax.
Parameters
• [in] x_org: X coordinate of the disk center in world coordinates

• [in] y_org: Y coordinate of the disk center in world coordinates

• [in] phimin: start angle of the disk sector in degrees

• [in] phimax: end angle of the disk sector in degrees

• [in] rmin: inner radius of the punctured disk in world coordinates

• [in] rmax: outer radius of the disk in world coordinates

• [in] dimphi: Phi (X) dimension of the color index array

• [in] dimr: R (Y) dimension of the color index array

• [in] scol: number of leading columns in the color index array

• [in] srow: number of leading rows in the color index array

• [in] ncol: total number of columns in the color index array

• [in] nrow: total number of rows in the color index array

• [in] color: color index array

To draw a contiguous array as a complete disk use:

gr_polarcellarray(x_org, y_org, 0, 360, 0, rmax, dimphi, dimr, 1, 1, dimphi, dimr, color)


The additional parameters to the function can be used to further control the mapping from polar to cartesian coordinates.

If rmin is greater than 0 the input data is mapped to a punctured disk (or annulus) with an inner radius of rmin and an outer radius rmax. If rmin is greater than rmax the Y-axis of the array is reversed.

The parameter phimin and phimax can be used to map the data to a sector of the (punctured) disk starting at phimin and ending at phimax. If phimin is greater than phimax the X-axis is reversed. The visible sector is the one starting in mathematically positive direction (counterclockwise) at the smaller angle and ending at the larger angle. An example of the four possible options can be found below:

 phimin phimax Result 90 270 Left half visible, mapped counterclockwise 270 90 Left half visible, mapped clockwise -90 90 Right half visible, mapped counterclockwise 90 -90 Right half visible, mapped clockwise

scol and srow can be used to specify a (1-based) starting column and row in the color array. ncol and nrow specify the actual dimension of the array in the memory whereof dimphi and dimr values are mapped to the disk.

void gr_nonuniformpolarcellarray(double, double, double*, double*, int, int, int, int, int, int, int*)

Display a two dimensional color index array mapped to a disk using polar coordinates with nonuniform cell sizes.

The mapping of the polar coordinates and the drawing is performed simialr to

gr_polarcellarray with the difference that the individual cell sizes are specified allowing nonuniform sized cells.
Parameters
• [in] x_org: X coordinate of the disk center in world coordinates

• [in] y_org: Y coordinate of the disk center in world coordinates

• [in] phi: array with the angles of the disk sector in degrees

• [in] r: array with the radii of the disk in world coordinates

• [in] dimphi: Phi (X) dimension of the color index array

• [in] dimr: R (Y) dimension of the color index array

• [in] scol: number of leading columns in the color index array and the angle array

• [in] srow: number of leading rows in the color index array and the radii array

• [in] ncol: total number of columns in the color index array and the angle array

• [in] nrow: total number of rows in the color index array and the radii array

• [in] color: color index array

If dimphi and dimr are positive phi must contain dimphi+1 elements and r must contain dimr+1 elements and the elements i and i+1 are respectively the edges of the i-th cell.

If dimphi and dimr are negative phi must contain -dimphi elements and r must contain -dimr elements and the i-th element is the center of the i-th cell, and the first and last elements will also be the edges of the outer cells.

scol and srow can be used to specify a (1-based) starting column and row in the color, phi and r array. dimr and dimphi specify the actual dimension of the arrays in the memory whereof ncol and nrow values are displayed.

void gr_gdp(int, double*, double*, int, int, int*)
void gr_spline(int, double*, double*, int, int)

Generate a cubic spline-fit, starting from the first data point and ending at the last data point.

The values for

x and y are in world coordinates. The attributes that control the appearance of a spline-fit are linetype, linewidth and color index.
Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] m: The number of points in the polygon to be drawn (m > n)

• [in] method: The smoothing method

If method is > 0, then a generalized cross-validated smoothing spline is calculated. If method is 0, then an interpolating natural cubic spline is calculated. If method is < -1, then a cubic B-spline is calculated.

void gr_gridit(int, double*, double*, double*, int, int, double*, double*, double*)

Interpolate data from arbitrary points at points on a rectangular grid.

Parameters
• [in] nd: The number of input points

• [in] xd: A pointer to the X coordinates of the input points

• [in] yd: A pointer to the Y coordinates of the input points

• [in] zd: A pointer to the values of the points

• [in] nx: The number of points in X direction for the output grid

• [in] ny: The number of points in Y direction for the output grid

• [out] x: A pointer to the points in X direction for the output grid

• [out] y: A pointer to the points in Y direction for the output grid

• [out] z: A pointer to the interpolated values on the nx x ny grid points

void gr_setlinetype(int)

Specify the line style for polylines.

The available line types are:

 LINETYPE_SOLID 1 Solid line LINETYPE_DASHED 2 Dashed line LINETYPE_DOTTED 3 Dotted line LINETYPE_DASHED_DOTTED 4 Dashed-dotted line LINETYPE_DASH_2_DOT -1 Sequence of one dash followed by two dots LINETYPE_DASH_3_DOT -2 Sequence of one dash followed by three dots LINETYPE_LONG_DASH -3 Sequence of long dashes LINETYPE_LONG_SHORT_DASH -4 Sequence of a long dash followed by a short dash LINETYPE_SPACED_DASH -5 Sequence of dashes double spaced LINETYPE_SPACED_DOT -6 Sequence of dots double spaced LINETYPE_DOUBLE_DOT -7 Sequence of pairs of dots LINETYPE_TRIPLE_DOT -8 Sequence of groups of three dots

Parameters
• [in] type: The polyline line style

void gr_inqlinetype(int*)
void gr_setlinewidth(double)

Define the line width of subsequent polyline output primitives.

The line width is calculated as the nominal line width generated on the workstation multiplied by the line width scale factor. This value is mapped by the workstation to the nearest available line width. The default line width is 1.0, or 1 times the line width generated on the graphics device.

Parameters
• [in] width: The polyline line width scale factor

void gr_inqlinewidth(double*)
void gr_setlinecolorind(int)

Define the color of subsequent polyline output primitives.

Parameters
• [in] color: The polyline color index (COLOR < 1256)

void gr_inqlinecolorind(int*)
void gr_setmarkertype(int)

Specifiy the marker type for polymarkers.

The available marker types are:

 MARKERTYPE_DOT 1 Smallest displayable dot MARKERTYPE_PLUS 2 Plus sign MARKERTYPE_ASTERISK 3 Asterisk MARKERTYPE_CIRCLE 4 Hollow circle MARKERTYPE_DIAGONAL_CROSS 5 Diagonal cross MARKERTYPE_SOLID_CIRCLE -1 Filled circle MARKERTYPE_TRIANGLE_UP -2 Hollow triangle pointing upward MARKERTYPE_SOLID_TRI_UP -3 Filled triangle pointing upward MARKERTYPE_TRIANGLE_DOWN -4 Hollow triangle pointing downward MARKERTYPE_SOLID_TRI_DOWN -5 Filled triangle pointing downward MARKERTYPE_SQUARE -6 Hollow square MARKERTYPE_SOLID_SQUARE -7 Filled square MARKERTYPE_BOWTIE -8 Hollow bowtie MARKERTYPE_SOLID_BOWTIE -9 Filled bowtie MARKERTYPE_HGLASS -10 Hollow hourglass MARKERTYPE_SOLID_HGLASS -11 Filled hourglass MARKERTYPE_DIAMOND -12 Hollow diamond MARKERTYPE_SOLID_DIAMOND -13 Filled Diamond MARKERTYPE_STAR -14 Hollow star MARKERTYPE_SOLID_STAR -15 Filled Star MARKERTYPE_TRI_UP_DOWN -16 Hollow triangles pointing up and down overlaid MARKERTYPE_SOLID_TRI_RIGHT -17 Filled triangle point right MARKERTYPE_SOLID_TRI_LEFT -18 Filled triangle pointing left MARKERTYPE_HOLLOW PLUS -19 Hollow plus sign MARKERTYPE_SOLID PLUS -20 Solid plus sign MARKERTYPE_PENTAGON -21 Pentagon MARKERTYPE_HEXAGON -22 Hexagon MARKERTYPE_HEPTAGON -23 Heptagon MARKERTYPE_OCTAGON -24 Octagon MARKERTYPE_STAR_4 -25 4-pointed star MARKERTYPE_STAR_5 -26 5-pointed star (pentagram) MARKERTYPE_STAR_6 -27 6-pointed star (hexagram) MARKERTYPE_STAR_7 -28 7-pointed star (heptagram) MARKERTYPE_STAR_8 -29 8-pointed star (octagram) MARKERTYPE_VLINE -30 verical line MARKERTYPE_HLINE -31 horizontal line MARKERTYPE_OMARK -32 o-mark

Parameters
• [in] type: The polymarker marker type

Polymarkers appear centered over their specified coordinates.

void gr_inqmarkertype(int*)
void gr_setmarkersize(double)

Specify the marker size for polymarkers.

The polymarker size is calculated as the nominal size generated on the graphics device multiplied by the marker size scale factor.

Parameters
• [in] size: Scale factor applied to the nominal marker size

void gr_inqmarkersize(double*)

Inquire the marker size for polymarkers.

Parameters
• [out] size: Scale factor applied to the nominal marker size

void gr_setmarkercolorind(int)

Define the color of subsequent polymarker output primitives.

Parameters
• [in] color: The polymarker color index (COLOR < 1256)

void gr_inqmarkercolorind(int*)
void gr_settextfontprec(int, int)

Specify the text font and precision for subsequent text output primitives.

The available text fonts are:

 FONT_TIMES_ROMAN 101 FONT_TIMES_ITALIC 102 FONT_TIMES_BOLD 103 FONT_TIMES_BOLDITALIC 104 FONT_HELVETICA 105 FONT_HELVETICA_OBLIQUE 106 FONT_HELVETICA_BOLD 107 FONT_HELVETICA_BOLDOBLIQUE 108 FONT_COURIER 109 FONT_COURIER_OBLIQUE 110 FONT_COURIER_BOLD 111 FONT_COURIER_BOLDOBLIQUE 112 FONT_SYMBOL 113 FONT_BOOKMAN_LIGHT 114 FONT_BOOKMAN_LIGHTITALIC 115 FONT_BOOKMAN_DEMI 116 FONT_BOOKMAN_DEMIITALIC 117 FONT_NEWCENTURYSCHLBK_ROMAN 118 FONT_NEWCENTURYSCHLBK_ITALIC 119 FONT_NEWCENTURYSCHLBK_BOLD 120 FONT_NEWCENTURYSCHLBK_BOLDITALIC 121 FONT_AVANTGARDE_BOOK 122 FONT_AVANTGARDE_BOOKOBLIQUE 123 FONT_AVANTGARDE_DEMI 124 FONT_AVANTGARDE_DEMIOBLIQUE 125 FONT_PALATINO_ROMAN 126 FONT_PALATINO_ITALIC 127 FONT_PALATINO_BOLD 128 FONT_PALATINO_BOLDITALIC 129 FONT_ZAPFCHANCERY_MEDIUMITALIC 130 FONT_ZAPFDINGBATS 131 FONT_COMPUTERMODERN 232 FONT_DEJAVUSANS 233

The available text precisions are:

 TEXT_PRECISION_STRING 0 String precision (higher quality) TEXT_PRECISION_CHAR 1 Character precision (medium quality) TEXT_PRECISION_STROKE 2 Stroke precision (lower quality) TEXT_PRECISION_OUTLINE 3 Outline precision (highest quality)

Parameters
• [in] font: Text font (see tables)

• [in] precision: Text precision (see table below)

The appearance of a font depends on the text precision value specified. STRING, CHARACTER, STROKE or OUTLINE precision allows for a greater or lesser realization of the text primitives, for efficiency. STRING is the default precision for GR and produces the high quality output using either native font rendering or FreeType. OUTLINE uses the GR path rendering functions to draw individual glyphs and produces the highest quality output.

void gr_setcharexpan(double)

Set the current character expansion factor (width to height ratio).

This function defines the width of subsequent text output primitives. The expansion factor alters the width of the generated characters, but not their height. The default text expansion factor is 1, or one times the normal width-to-height ratio of the text.

Parameters
• [in] factor: Text expansion factor applied to the nominal text width-to-height ratio

void gr_setcharspace(double)
void gr_settextcolorind(int)

Set the current text color index.

This function defines the color of subsequent text output primitives. GR uses the default foreground color (black=1) for the default text color index.

Parameters
• [in] color: The text color index (COLOR < 1256)

void gr_inqtextcolorind(int*)

Gets the current text color index.

This function gets the color of text output primitives.

Parameters
• [out] color: The text color index (COLOR < 1256)

void gr_setcharheight(double)

Set the current character height.

This function defines the height of subsequent text output primitives. Text height is defined as a percentage of the default window. GR uses the default text height of 0.027 (2.7% of the height of the default window).

Parameters
• [in] height: Text height value

void gr_inqcharheight(double*)

Gets the current character height..

This function gets the height of text output primitives. Text height is defined as a percentage of the default window. GR uses the default text height of 0.027 (2.7% of the height of the default window).

Parameters
• [out] height: Text height value

void gr_setcharup(double, double)

Set the current character text angle up vector.

This function defines the vertical rotation of subsequent text output primitives. The text up vector is initially set to (0, 1), horizontal to the baseline.

Parameters
• [in] ux: X coordinate of the text up vector

• [in] uy: Y coordinate of the text up vector

void gr_settextpath(int)

Define the current direction in which subsequent text will be drawn.

 TEXT_PATH_RIGHT 0 left-to-right TEXT_PATH_LEFT 1 right-to-left TEXT_PATH_UP 2 downside-up TEXT_PATH_DOWN 3 upside-down

Parameters
• [in] path: Text path (see table)

void gr_settextalign(int, int)

Set the current horizontal and vertical alignment for text.

 TEXT_HALIGN_NORMAL 0 TEXT_HALIGN_LEFT 1 Left justify TEXT_HALIGN_CENTER 2 Center justify TEXT_HALIGN_RIGHT 3 Right justify
 TEXT_VALIGN_NORMAL 0 TEXT_VALIGN_TOP 1 Align with the top of the characters TEXT_VALIGN_CAP 2 Aligned with the cap of the characters TEXT_VALIGN_HALF 3 Aligned with the half line of the characters TEXT_VALIGN_BASE 4 Aligned with the base line of the characters TEXT_VALIGN_BOTTOM 5 Aligned with the bottom line of the characters

Parameters
• [in] horizontal: Horizontal text alignment (see the table)

• [in] vertical: Vertical text alignment (see the table)

This function specifies how the characters in a text primitive will be aligned in horizontal and vertical space. The default text alignment indicates horizontal left alignment and vertical baseline alignment.

void gr_setfillintstyle(int)

Set the fill area interior style to be used for fill areas.

 HOLLOW 0 No filling. Just draw the bounding polyline SOLID 1 Fill the interior of the polygon using the fill color index PATTERN 2 Fill the interior of the polygon using the style index as a pattern index HATCH 3 Fill the interior of the polygon using the style index as a cross-hatched style SOLID_WITH_BORDER 4 Fill the interior of the polygon using the fill color index and draw the bounding polyline

Parameters
• [in] style: The style of fill to be used

This function defines the interior style for subsequent fill area output primitives. The default interior style is HOLLOW.

void gr_inqfillintstyle(int*)

Set the fill area interior style to be used for fill areas.

This function gets the currently set fill style.

Parameters
• [out] style: The currently set fill style

void gr_setfillstyle(int)

Set the fill area interior style to be used for fill areas.

This function specifies an index when PATTERN fill or HATCH fill is requested by the gr_setfillintstyle function. If the interior style is set to PATTERN, the fill style index points to a device-independent pattern table. If interior style is set to HATCH the fill style index indicates different hatch styles. If HOLLOW or SOLID is specified for the interior style, the fill style index is unused.

Parameters
• [in] index: The fill style index to be used

void gr_inqfillstyle(int*)

Get the fill area interior style to be used for fill areas.

This function gets the color index for PATTERN and HATCH fills.

Parameters
• [out] index: The currently set fill style color index

void gr_setfillcolorind(int)

Sets the current fill area color index.

This function defines the color of subsequent fill area output primitives. GR uses the default foreground color (black=1) for the default fill area color index.

Parameters
• [in] color: The fill area color index (COLOR < 1256)

void gr_inqfillcolorind(int*)

Gets the current fill area color index.

This function gets the color of fill area output primitives.

Parameters
• [out] color: The fill area color index (COLOR < 1256)

void gr_setcolorrep(int, double, double, double)

Redefine an existing color index representation by specifying an RGB color triplet.

Parameters
• [in] index: Color index in the range 0 to 1256

• [in] red: Red intensity in the range 0.0 to 1.0

• [in] green: Green intensity in the range 0.0 to 1.0

• [in] blue: Blue intensity in the range 0.0 to 1.0

void gr_setwindow(double, double, double, double)

Establishes a window, or rectangular subspace, of world coordinates to be plotted. If you desire log scaling or mirror-imaging of axes, use the gr_setscale function.

This function defines the rectangular portion of the World Coordinate space (WC) to be associated with the specified normalization transformation. The WC window and the Normalized Device Coordinates (NDC) viewport define the normalization transformation through which all output primitives are mapped. The WC window is mapped onto the rectangular NDC viewport which is, in turn, mapped onto the display surface of the open and active workstation, in device coordinates. By default, GR uses the range [0,1] x [0,1], in world coordinates, as the normalization transformation window.

Parameters
• [in] xmin: The left horizontal coordinate of the window (xmin < xmax).

• [in] xmax: The right horizontal coordinate of the window (xmin < xmax).

• [in] ymin: The bottom vertical coordinate of the window (ymin < ymax).

• [in] ymax: The top vertical coordinate of the window (ymin < ymax).

void gr_inqwindow(double*, double*, double*, double*)
void gr_setviewport(double, double, double, double)

Establishes a rectangular subspace of normalized device coordinates.

This function defines the rectangular portion of the Normalized Device Coordinate (NDC) space to be associated with the specified normalization transformation. The NDC viewport and World Coordinate (WC) window define the normalization transformation through which all output primitives pass. The WC window is mapped onto the rectangular NDC viewport which is, in turn, mapped onto the display surface of the open and active workstation, in device coordinates.

Parameters
• [in] xmin: The left horizontal coordinate of the viewport (0 <= xmin < xmax).

• [in] xmax: The right horizontal coordinate of the viewport (xmin < xmax <= 1).

• [in] ymin: The bottom vertical coordinate of the viewport (0 <= ymin < ymax).

• [in] ymax: The top vertical coordinate of the viewport (ymin < ymax <= 1).

void gr_inqviewport(double*, double*, double*, double*)
void gr_selntran(int)

Select a predefined transformation from world coordinates to normalized device coordinates.

 0 Selects the identity transformation in which both the window and viewport have the range of 0 to 1 >= 1 Selects a normalization transformation as defined by setwindow and setviewport

Parameters
• [in] transform: A normalization transformation number.

void gr_setclip(int)

Set the clipping indicator.

 0 Clipping is off. Data outside of the window will be drawn. 1 Clipping is on. Data outside of the window will not be drawn.

Parameters
• [in] indicator: An indicator specifying whether clipping is on or off.

This function enables or disables clipping of the image drawn in the current window. Clipping is defined as the removal of those portions of the graph that lie outside of the defined viewport. If clipping is on, GR does not draw generated output primitives past the viewport boundaries. If clipping is off, primitives may exceed the viewport boundaries, and they will be drawn to the edge of the workstation window. By default, clipping is on.

void gr_setwswindow(double, double, double, double)

Set the area of the NDC viewport that is to be drawn in the workstation window.

This function defines the rectangular area of the Normalized Device Coordinate space to be output to the device. By default, the workstation transformation will map the range [0,1] x [0,1] in NDC onto the largest square on the workstation’s display surface. The aspect ratio of the workstation window is maintained at 1 to 1.

Parameters
• [in] xmin: The left horizontal coordinate of the workstation window (0 <= xmin < xmax).

• [in] xmax: The right horizontal coordinate of the workstation window (xmin < xmax <= 1).

• [in] ymin: The bottom vertical coordinate of the workstation window (0 <= ymin < ymax).

• [in] ymax: The top vertical coordinate of the workstation window (ymin < ymax <= 1).

void gr_setwsviewport(double, double, double, double)

Define the size of the workstation graphics window in meters.

This function places a workstation window on the display of the specified size in meters. This command allows the workstation window to be accurately sized for a display or hardcopy device, and is often useful for sizing graphs for desktop publishing applications.

Parameters
• [in] xmin: The left horizontal coordinate of the workstation window.

• [in] xmax: The right horizontal coordinate of the workstation window.

• [in] ymin: The bottom vertical coordinate of the workstation window.

• [in] ymax: The top vertical coordinate of the workstation window.

void gr_createseg(int)
void gr_copysegws(int)
void gr_redrawsegws(void)
void gr_setsegtran(int, double, double, double, double, double, double, double)
void gr_closeseg(void)
void gr_emergencyclosegks(void)
void gr_updategks(void)
int gr_setspace(double, double, int, int)

Set the abstract Z-space used for mapping three-dimensional output primitives into the current world coordinate space.

This function establishes the limits of an abstract Z-axis and defines the angles for rotation and for the viewing angle (tilt) of a simulated three-dimensional graph, used for mapping corresponding output primitives into the current window. These settings are used for all subsequent three-dimensional output primitives until other values are specified. Angles of rotation and viewing angle must be specified between 0 and 90 degrees.

Parameters
• [in] zmin: Minimum value for the Z-axis.

• [in] zmax: Maximum value for the Z-axis.

• [in] rotation: Angle for the rotation of the X axis, in degrees.

• [in] tilt: Viewing angle of the Z axis, in degrees.

void gr_inqspace(double*, double*, int*, int*)
int gr_setscale(int)

Set the type of transformation to be used for subsequent GR output primitives.

 OPTION_X_LOG Logarithmic X-axis OPTION_Y_LOG Logarithmic Y-axis OPTION_Z_LOG Logarithmic Z-axis OPTION_FLIP_X Flip X-axis OPTION_FLIP_Y Flip Y-axis OPTION_FLIP_Z Flip Z-axis

Parameters
• [in] options: Scale specification (see table)

This function defines the current transformation according to the given scale specification which may be or’ed together using any of the above options. GR uses these options for all subsequent output primitives until another value is provided. The scale options are used to transform points from an abstract logarithmic or semi-logarithmic coordinate system, which may be flipped along each axis, into the world coordinate system.

Note

When applying a logarithmic transformation to a specific axis, the system assumes that the axes limits are greater than zero.

void gr_inqscale(int*)
int gr_textext(double, double, char*)

Draw a text at position x, y using the current text attributes. Strings can be defined to create basic mathematical expressions and Greek letters.

The values for X and Y are in normalized device coordinates. The attributes that control the appearance of text are text font and precision, character expansion factor, character spacing, text color index, character height, character up vector, text path and text alignment.

Parameters
• [in] x: The X coordinate of starting position of the text string

• [in] y: The Y coordinate of starting position of the text string

• [in] string: The text to be drawn

The character string is interpreted to be a simple mathematical formula. The following notations apply:

Subscripts and superscripts: These are indicated by carets (‘^’) and underscores (‘_’). If the sub/superscript contains more than one character, it must be enclosed in curly braces (‘{}’).

Fractions are typeset with A ‘/’ B, where A stands for the numerator and B for the denominator.

To include a Greek letter you must specify the corresponding keyword after a backslash (‘') character. The text translator produces uppercase or lowercase Greek letters depending on the case of the keyword.

 Letter Keyword $$A$$ $$\alpha$$ alpha $$B$$ $$\beta$$ beta $$\Gamma$$ $$\gamma$$ gamma $$\Delta$$ $$\delta$$ delta $$E$$ $$\epsilon$$ epsilon $$Z$$ $$\zeta$$ zeta $$H$$ $$\eta$$ eta $$\Theta$$ $$\theta$$ theta $$I$$ $$\iota$$ iota $$K$$ $$\kappa$$ kappa $$\Lambda$$ $$\lambda$$ lambda $$M$$ $$\mu$$ mu $$N$$ $$\nu$$ v $$\Xi$$ $$\xi$$ xi $$O$$ $$o$$ omicron $$\Pi$$ $$\pi$$ pi $$P$$ $$\rho$$ rho $$\Sigma$$ $$\sigma$$ sigma $$T$$ $$\tau$$ tau $$\Upsilon$$ $$\upsilon$$ upsilon $$\Phi$$ $$\phi$$ phi $$X$$ $$\chi$$ chi $$\Psi$$ $$\psi$$ psi $$\Omega$$ $$\omega$$ omega

For more sophisticated mathematical formulas, you should use the gr_mathtex function.

Note: ‘v’ is a replacement for ‘nu’ which would conflict with ‘

’ (newline)

void gr_inqtextext(double, double, char*, double*, double*)
void gr_axes(double, double, double, double, int, int, double)

Draw X and Y coordinate axes with linearly and/or logarithmically spaced tick marks.

Tick marks are positioned along each axis so that major tick marks fall on the axes origin (whether visible or not). Major tick marks are labeled with the corresponding data values. Axes are drawn according to the scale of the window. Axes and tick marks are drawn using solid lines; line color and width can be modified using the gr_setlinetype and gr_setlinewidth functions. Axes are drawn according to the linear or logarithmic transformation established by the gr_setscale function.

Parameters
• [in] x_tick: The interval between minor tick marks on the X axis.

• [in] y_tick: The interval between minor tick marks on the Y axis.

• [in] x_org: The world coordinate of the origin (point of intersection) of the X axis.

• [in] y_org: The world coordinate of the origin (point of intersection) of the Y axis.

• [in] major_x: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis.

• [in] major_y: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis.

• [in] tick_size: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa).

void gr_axeslbl(double, double, double, double, int, int, double, void (*)(double, double, const char*, double), void (*)(double, double, const char*, double))

Create axes in the current workspace and supply a custom function for changing the behaviour of the tick labels.

Similar to gr_axes() but allows more fine-grained control over tick labels and text positioning by supplying callback functions. Within the callback function you can use normal GR text primitives for performing any manipulations on the label text.

See gr_axes() for more details on drawing axes.

Parameters
• [in] x_tick: The interval between minor tick marks on the X axis.

• [in] y_tick: The interval between minor tick marks on the Y axis.

• [in] x_org: The world coordinate of the origin (point of intersection) of the X axis.

• [in] y_org: The world coordinate of the origin (point of intersection) of the Y axis.

• [in] major_x: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis.

• [in] major_y: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis.

• [in] tick_size: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa).

• [in] fpx: Function pointer to a function that returns a label for a given tick on the X axis. The callback function should have the following arguments:

• [in] x: NDC of the label in X direction.

• [in] y: NDC of the label in Y direction.

• [in] svalue: Internal string representation of the text drawn by GR at (x,y).

• [in] value: Floating point representation of the label drawn at (x,y).

• [in] fpy: Exactly same as the fpx above, but for the the Y axis.

void gr_grid(double, double, double, double, int, int)

Draw a linear and/or logarithmic grid.

Major grid lines correspond to the axes origin and major tick marks whether visible or not. Minor grid lines are drawn at points equal to minor tick marks. Major grid lines are drawn using black lines and minor grid lines are drawn using gray lines.

Parameters
• [in] x_tick: The length in world coordinates of the interval between minor grid lines in X direction.

• [in] y_tick: The length in world coordinates of the interval between minor grid lines in Y direction.

• [in] x_org: The world coordinate of the origin (point of intersection) of the X axis.

• [in] y_org: The world coordinate of the origin (point of intersection) of the Y axis.

• [in] major_x: Unitless integer value specifying the number of minor grid lines between major grid lines on the X axis. Values of 0 or 1 imply no grid lines.

• [in] major_y: Unitless integer value specifying the number of minor grid lines between major grid lines on the Y axis. Values of 0 or 1 imply no grid lines.

void gr_grid3d(double, double, double, double, double, double, int, int, int)

Draw a linear and/or logarithmic grid.

Major grid lines correspond to the axes origin and major tick marks whether visible or not. Minor grid lines are drawn at points equal to minor tick marks. Major grid lines are drawn using black lines and minor grid lines are drawn using gray lines.

Parameters
• [in] x_tick: The length in world coordinates of the interval between minor grid lines in X direction.

• [in] y_tick: The length in world coordinates of the interval between minor grid lines in Y direction.

• [in] z_tick: The length in world coordinates of the interval between minor grid lines in Z direction.

• [in] x_org: The world coordinate of the origin (point of intersection) of the X axis.

• [in] y_org: The world coordinate of the origin (point of intersection) of the Y axis.

• [in] z_org: The world coordinate of the origin (point of intersection) of the Z axis.

• [in] major_x: Unitless integer value specifying the number of minor grid lines between major grid lines on the X axis. Values of 0 or 1 imply no grid lines.

• [in] major_y: Unitless integer value specifying the number of minor grid lines between major grid lines on the Y axis. Values of 0 or 1 imply no grid lines.

• [in] major_z: Unitless integer value specifying the number of minor grid lines between major grid lines on the Z axis. Values of 0 or 1 imply no grid lines.

void gr_verrorbars(int, double*, double*, double*, double*)

Draw a standard vertical error bar graph.

Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] e1: A pointer to the absolute values of the lower error bar data

• [in] e2: A pointer to the absolute values of the upper error bar data

void gr_herrorbars(int, double*, double*, double*, double*)

Draw a standard horizontal error bar graph.

Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] e1: A pointer to the absolute values of the lower error bar data

• [in] e2: A pointer to the absolute values of the upper error bar data

void gr_polyline3d(int, double*, double*, double*)

Draw a 3D curve using the current line attributes, starting from the first data point and ending at the last data point.

The values for x, y and z are in world coordinates. The attributes that control the appearance of a polyline are linetype, linewidth and color index.

Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] pz: A pointer to the Z coordinates

void gr_polymarker3d(int, double*, double*, double*)

Draw marker symbols centered at the given 3D data points.

The values for x, y and z are in world coordinates. The attributes that control the appearance of a polymarker are marker type, marker size scale factor and color index.

Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] pz: A pointer to the Z coordinates

void gr_axes3d(double, double, double, double, double, double, int, int, int, double)

Draw X, Y and Z coordinate axes with linearly and/or logarithmically spaced tick marks.

Tick marks are positioned along each axis so that major tick marks fall on the axes origin (whether visible or not). Major tick marks are labeled with the corresponding data values. Axes are drawn according to the scale of the window. Axes and tick marks are drawn using solid lines; line color and width can be modified using the gr_setlinetype and gr_setlinewidth functions. Axes are drawn according to the linear or logarithmic transformation established by the gr_setscale function.

Parameters
• [in] x_tick: The length in world coordinates of the interval between minor grid lines in X direction.

• [in] y_tick: The length in world coordinates of the interval between minor grid lines in Y direction.

• [in] z_tick: The length in world coordinates of the interval between minor grid lines in Z direction.

• [in] x_org: The world coordinate of the origin (point of intersection) of the X axis.

• [in] y_org: The world coordinate of the origin (point of intersection) of the Y axis.

• [in] z_org: The world coordinate of the origin (point of intersection) of the Z axis.

• [in] major_x: Unitless integer value specifying the number of minor grid lines between major grid lines on the X axis. Values of 0 or 1 imply no grid lines.

• [in] major_y: Unitless integer value specifying the number of minor grid lines between major grid lines on the Y axis. Values of 0 or 1 imply no grid lines.

• [in] major_z: Unitless integer value specifying the number of minor grid lines between major grid lines on the Z axis. Values of 0 or 1 imply no grid lines.

• [in] tick_size: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa).

void gr_titles3d(char*, char*, char*)

Display axis titles just outside of their respective axes.

Parameters
• [in] x_title: The text to be displayed on the X axis

• [in] y_title: The text to be displayed on the Y axis

• [in] z_title: The text to be displayed on the Z axis

void gr_surface(int, int, double*, double*, double*, int)

Draw a three-dimensional surface plot for the given data points.

x and y define a grid. z is a singly dimensioned array containing at least nx * ny data points. z describes the surface height at each point on the grid. Data is ordered as shown in the following table:

Parameters
• [in] nx: The number of points along the X axis

• [in] ny: The number of points along the Y axis

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] pz: A pointer to the Z coordinates

• [in] option: Surface display option (see table)

 LINES 0 Use X Y polylines to denote the surface MESH 1 Use a wire grid to denote the surface FILLED_MESH 2 Applies an opaque grid to the surface Z_SHADED_MESH 3 Applies Z-value shading to the surface COLORED_MESH 4 Applies a colored grid to the surface CELL_ARRAY 5 Applies a grid of individually-colored cells to the surface SHADED_MESH 6 Applies light source shading to the 3-D surface

To see option 2 correctly change linecolorind or fillcolorind. Both default values are black.

void gr_contour(int, int, int, double*, double*, double*, double*, int)

Draw contours of a three-dimensional data set whose values are specified over a rectangular mesh. Contour lines may optionally be labeled.

Parameters
• [in] nx: The number of points along the X axis

• [in] ny: The number of points along the Y axis

• [in] nh: The number of height values

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] h: A pointer to the height values

• [in] pz: A pointer to the Z coordinates

• [in] major_h: Directs GR to label contour lines. For example, a value of 3 would label every third line. A value of 1 will label every line. A value of 0 produces no labels. To produce colored contour lines, add an offset of 1000 to major_h

void gr_contourf(int, int, int, double*, double*, double*, double*, int)

Draw filled contour plot of a three-dimensional data set whose values are specified over a rectangular mesh.

Parameters
• [in] nx: The number of points along the X axis

• [in] ny: The number of points along the Y axis

• [in] nh: The number of height values. 0 for default contours.

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] h: A pointer to the height values. If NULL, use nh evenly distributed height values between minimum and maximum Z value.

• [in] pz: A pointer to the Z coordinates

• [in] major_h: Directs GR to label contour lines. For example, a value of 3 would label every third line. A value of 1 will label every line. A value of 0 produces no labels. To produce colored contour lines, add an offset of 1000 to major_h

void gr_tricontour(int, double*, double*, double*, int, double*)

Draw a contour plot for the given triangle mesh.

Parameters
• [in] npoints: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

• [in] z: A pointer to the Z coordinates

• [in] nlevels: The number of contour levels

• [in] levels: A pointer to the contour levels

int gr_hexbin(int, double*, double*, int)
void gr_setcolormap(int)

Set the currently used colormap.

A list of colormaps can be found at:

https://gr-framework.org/colormaps.html
Parameters
• [in] index: Colormap index

Using a negative index will use the reverse of the selected colormap.

void gr_inqcolormap(int*)
void gr_setcolormapfromrgb(int n, double *r, double *g, double *b, double *x)

Define a colormap by a list of RGB colors.

This function defines a colormap using the n given color intensities. If less than 256 colors are provided the colors intensities are linear interpolated. If x is NULL the given color values are evenly distributed in the colormap. Otherwise the normalized value of x defines the position of the color in the colormap.

Parameters
• [in] n: The number of colors

• [in] r: A pointer to the red intensities in range 0.0 to 1.0

• [in] g: A pointer to the green intensities in range 0.0 to 1.0

• [in] b: A pointer to the blue intensities in range 0.0 to 1.0

• [in] x: A pointer to the positions of the corresponding color in the resulting colormap or NULL. The values of x must increase monotonically from 0.0 to 1.0. If x is NULL the given colors are evenly distributed in the colormap.

void gr_inqcolormapinds(int*, int*)

Inquire the color index range of the current colormap.

Parameters
• [out] first_color_ind: The color index of the first color

• [out] last_color_ind: The color index of the last color

void gr_colorbar(void)
void gr_inqcolor(int, int*)
int gr_inqcolorfromrgb(double, double, double)
void gr_hsvtorgb(double h, double s, double v, double *r, double *g, double *b)
double gr_tick(double, double)
int gr_validaterange(double, double)
void gr_adjustlimits(double*, double*)
void gr_adjustrange(double*, double*)
void gr_beginprint(char*)

Open and activate a print device.

This function opens an additional graphics output device. The device type is obtained from the given file extension. The following file types are supported:

Parameters
• [in] pathname: Filename for the print device.

The following file types are supported:

 .ps, .eps PostScript .pdf Portable Document Format .bmp Windows Bitmap (BMP) .jpeg, .jpg JPEG image file .png Portable Network Graphics file (PNG) .tiff, .tif Tagged Image File Format (TIFF) .svg Scalable Vector Graphics .wmf Windows Metafile .mp4 MPEG-4 video file .webm WebM video file .ogg Ogg video file

void gr_beginprintext(char*, char*, char*, char*)

Open and activate a print device with the given layout attributes.

The available formats are:

 A4 0.210 x 0.297 B5 0.176 x 0.250 Letter 0.216 x 0.279 Legal 0.216 x 0.356 Executive 0.191 x 0.254 A0 0.841 x 1.189 A1 0.594 x 0.841 A2 0.420 x 0.594 A3 0.297 x 0.420 A5 0.148 x 0.210 A6 0.105 x 0.148 A7 0.074 x 0.105 A8 0.052 x 0.074 A9 0.037 x 0.052 B0 1.000 x 1.414 B1 0.500 x 0.707 B10 0.031 x 0.044 B2 0.500 x 0.707 B3 0.353 x 0.500 B4 0.250 x 0.353 B6 0.125 x 0.176 B7 0.088 x 0.125 B8 0.062 x 0.088 B9 0.044 x 0.062 C5E 0.163 x 0.229 Comm10E 0.105 x 0.241 DLE 0.110 x 0.220 Folio 0.210 x 0.330 Ledger 0.432 x 0.279 Tabloid 0.279 x 0.432

Parameters
• [in] pathname: Filename for the print device.

• [in] mode: Output mode (Color, GrayScale)

• [in] format: Output format (see table)

• [in] orientation: Page orientation (Landscape, Portait)

void gr_endprint(void)
void gr_ndctowc(double*, double*)
void gr_wctondc(double*, double*)
void gr_wc3towc(double*, double*, double*)
void gr_drawrect(double, double, double, double)

Draw a rectangle using the current line attributes.

Parameters
• [in] xmin: Left edge of the rectangle

• [in] xmax: Right edge of the rectangle

• [in] ymin: Bottom edge of the rectangle

• [in] ymax: Upper edge of the rectangle

void gr_fillrect(double, double, double, double)

Draw a filled rectangle using the current fill attributes.

Parameters
• [in] xmin: Left edge of the rectangle

• [in] xmax: Right edge of the rectangle

• [in] ymin: Bottom edge of the rectangle

• [in] ymax: Upper edge of the rectangle

void gr_drawarc(double, double, double, double, double, double)

Draw a circular or elliptical arc covering the specified rectangle.

The resulting arc begins at a1 and ends at a2 degrees. Angles are interpreted such that 0 degrees is at the 3 o’clock position. The center of the arc is the center of the given rectangle.

Parameters
• [in] xmin: Left edge of the rectangle

• [in] xmax: Right edge of the rectangle

• [in] ymin: Bottom edge of the rectangle

• [in] ymax: Upper edge of the rectangle

• [in] a1: The start angle

• [in] a2: The end angle

void gr_fillarc(double, double, double, double, double, double)

Fill a circular or elliptical arc covering the specified rectangle.

The resulting arc begins at a1 and ends at a2 degrees. Angles are interpreted such that 0 degrees is at the 3 o’clock position. The center of the arc is the center of the given rectangle.

Parameters
• [in] xmin: Left edge of the rectangle

• [in] xmax: Right edge of the rectangle

• [in] ymin: Bottom edge of the rectangle

• [in] ymax: Upper edge of the rectangle

• [in] a1: The start angle

• [in] a2: The end angle

void gr_drawpath(int, vertex_t*, unsigned char*, int)

Draw simple and compound outlines consisting of line segments and bezier curves.

The following path codes are recognized:

 STOP end the entire path MOVETO move to the given vertex LINETO draw a line from the current position to the given vertex CURVE3 draw a quadratic Bezier curve CURVE4 draw a cubic Bezier curve CLOSEPOLY draw a line segment to the start point of the current path

Parameters
• [in] n: The number of vertices

• [in] vertices: A pointer to the vertices

• [in] codes: A pointer to the path codes

• [in] fill: A flag indication whether resulting path is to be filled or not

void gr_setarrowstyle(int)

Set the arrow style to be used for subsequent arrow commands.

This function defines the arrow style for subsequent arrow primitives. The default arrow style is 1.

Parameters
• [in] style: The arrow style to be used

 1 simple, single-ended 2 simple, single-ended, acute head 3 hollow, single-ended 4 filled, single-ended 5 triangle, single-ended 6 filled triangle, single-ended 7 kite, single-ended 8 filled kite, single-ended 9 simple, double-ended 10 simple, double-ended, acute head 11 hollow, double-ended 12 filled, double-ended 13 triangle, double-ended 14 filled triangle, double-ended 15 kite, double-ended 16 filled kite, double-ended 17 double line, single-ended 18 double line, double-ended

void gr_setarrowsize(double)

Set the arrow size to be used for subsequent arrow commands.

This function defines the arrow size for subsequent arrow primitives. The default arrow size is 1.

Parameters
• [in] size: The arrow size to be used

void gr_drawarrow(double, double, double, double)

Draw an arrow between two points.

Different arrow styles (angles between arrow tail and wing, optionally filled heads, double headed arrows) are available and can be set with the gr_setarrowstyle function.

Parameters
• [in] x1: The X coordinate of the arrow start point (tail)

• [in] y1: The Y coordinate of the arrow start point (tail)

• [in] x2: The X coordinate of the arrow end point (head)

• [in] y2: The Y coordinate of the arrow end point (head)

int gr_readimage(char*, int*, int*, int**)
void gr_drawimage(double, double, double, double, int, int, int*, int)

Draw an image into a given rectangular area.

The points (xmin, ymin) and (xmax, ymax) are world coordinates defining diagonally opposite corner points of a rectangle. This rectangle is divided into width by height cells. The two-dimensional array data specifies colors for each cell.

Parameters
• [in] xmin: X coordinate of the lower left point of the rectangle

• [in] ymin: Y coordinate of the lower left point of the rectangle

• [in] xmax: X coordinate of the upper right point of the rectangle

• [in] ymax: Y coordinate of the upper right point of the rectangle

• [in] width: X dimension of the color index array

• [in] height: Y dimension of the color index array

• [in] data: color array

• [in] model: color model

The available color models are:

 MODEL_RGB 0 AABBGGRR MODEL_HSV 1 AAVVSSHH

int gr_importgraphics(char*)
void gr_setshadow(double, double, double)

Allows drawing of shadows, realized by images painted underneath, and offset from, graphics objects such that the shadow mimics the effect of a light source cast on the graphics objects.

Parameters
• [in] offsetx: An x-offset, which specifies how far in the horizontal direction the shadow is offset from the object

• [in] offsety: A y-offset, which specifies how far in the vertical direction the shadow is offset from the object

• [in] blur: A blur value, which specifies whether the object has a hard or a diffuse edge

void gr_settransparency(double)

Set the value of the alpha component associated with GR colors.

Parameters
• [in] alpha: An alpha value (0.0 - 1.0)

void gr_setcoordxform(double[3][2])

Change the coordinate transformation according to the given matrix.

Parameters
• [in] mat: 2D transformation matrix

void gr_begingraphics(char*)

Open a file for graphics output.

gr_begingraphics allows to write all graphics output into a XML-formatted file until the gr_endgraphics functions is called. The resulting file may later be imported with the gr_importgraphics function.

Parameters
• [in] path: Filename for the graphics file.

void gr_endgraphics(void)
char *gr_getgraphics(void)
int gr_drawgraphics(char*)
void gr_mathtex(double, double, char*)

Generate a character string starting at the given location. Strings can be defined to create mathematical symbols and Greek letters using LaTeX syntax.

Parameters
• [in] x: The X coordinate of the starting position of the text string

• [in] y: The Y coordinate of the starting position of the text string

• [in] string: The text string to be drawn

void gr_inqmathtex(double, double, char*, double*, double*)
void gr_beginselection(int, int)
void gr_endselection(void)
void gr_moveselection(double, double)
void gr_resizeselection(int, double, double)
void gr_inqbbox(double*, double*, double*, double*)
double gr_precision(void)
void gr_setregenflags(int)
int gr_inqregenflags(void)
void gr_savestate(void)
void gr_restorestate(void)
void gr_selectcontext(int)
void gr_destroycontext(int)
int gr_uselinespec(char*)
void gr_delaunay(int, const double*, const double*, int*, int**)
void gr_reducepoints(int, const double*, const double*, int, double*, double*)

Reduces the number of points of the x and y array.

Parameters
• [in] n: the number of points of the x and y arrays

• [in] x: the x value array

• [in] y: the y value array

• [in] points: the requested number of points

• [out] x_array: the return array for the x values

• [out] y_array: the return array for the y values

void gr_trisurface(int, double*, double*, double*)

Draw a triangular surface plot for the given data points.

Parameters
• [in] n: The number of points

• [in] px: A pointer to the X coordinates

• [in] py: A pointer to the Y coordinates

• [in] pz: A pointer to the Z coordinates

void gr_gradient(int, int, double*, double*, double*, double*, double*)
void gr_quiver(int, int, double*, double*, double*, double*, int)
void gr_interp2(int nx, int ny, const double *x, const double *y, const double *z, int nxq, int nyq, const double *xq, const double *yq, double *zq, int method, double extrapval)

Interpolation in two dimensions using one of four different methods. The input points are located on a grid, described by nx, ny, x, y and z. The target grid ist described by nxq, nyq, xq and yq and the output is written to zq as a field of nxq * nyq values.

The available methods for interpolation are the following:

 INTERP2_NEAREST 0 Nearest neighbour interpolation INTERP2_LINEAR 1 Linear interpolation INTERP_2_SPLINE 2 Interpolation using natural cubic splines INTERP2_CUBIC 3 Cubic interpolation

Parameters
• [in] nx: The number of the input grid’s x-values

• [in] ny: The number of the input grid’s y-values

• [in] x: Pointer to the input grid’s x-values

• [in] y: Pointer to the input grid’s y-values

• [in] z: Pointer to the input grid’s z-values (num. of values: nx * ny)

• [in] nxq: The number of the target grid’s x-values

• [in] nyq: The number of the target grid’s y-values

• [in] xq: Pointer to the target grid’s x-values

• [in] yq: Pointer to the target grid’s y-values

• [out] zq: Pointer to the target grids’s z-values, used for output

• [in] method: Used method for interpolation

• [in] extrapval: The extrapolation value

const char *gr_version(void)

Returns the version string of the GR runtime.

Return

A pointer to the GR runtime version string.

void gr_shade(int, double*, double*, int, int, double*, int, int, int*)
void gr_shadepoints(int, double*, double*, int, int, int)

Display a point set as a aggregated and rasterized image.

The values for

x and y are in world coordinates.
Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

• [in] xform: The transformation type used for color mapping

• [in] w: The width of the grid used for rasterization

• [in] h: The height of the grid used for rasterization

The available transformation types are:

 XFORM_BOOLEAN 0 boolean XFORM_LINEAR 1 linear XFORM_LOG 2 logarithmic XFORM_LOGLOG 3 double logarithmic XFORM_CUBIC 4 cubic XFORM_EQUALIZED 5 histogram equalized

void gr_shadelines(int, double*, double*, int, int, int)

Display a line set as a aggregated and rasterized image.

The values for

x and y are in world coordinates. NaN values can be used to separate the point set into line segments.
Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

• [in] xform: The transformation type used for color mapping

• [in] w: The width of the grid used for rasterization

• [in] h: The height of the grid used for rasterization

The available transformation types are:

 XFORM_BOOLEAN 0 boolean XFORM_LINEAR 1 linear XFORM_LOG 2 logarithmic XFORM_LOGLOG 3 double logarithmic XFORM_CUBIC 4 cubic XFORM_EQUALIZED 5 histogram equalized

void gr_panzoom(double, double, double, double, double*, double*, double*, double*)
int gr_findboundary(int, double*, double*, double, double (*)(double, double), int, int*, )
void gr_setresamplemethod(unsigned int)

Set the resample method for resampling.

The available options are:

Parameters
• [in] flag: Resample method

 GKS_K_RESAMPLE_DEFAULT 0x00000000 default GKS_K_RESAMPLE_NEAREST 0x01010101 nearest neighbour GKS_K_RESAMPLE_LINEAR 0x02020202 linear GKS_K_RESAMPLE_LANCZOS 0x03030303 Lanczos

Alternatively, combinations of these methods can be selected for horizontal or vertical upsampling or downsampling:

 GKS_K_UPSAMPLE_VERTICAL_DEFAULT 0x00000000 default for vertical upsampling GKS_K_UPSAMPLE_HORIZONTAL_DEFAULT 0x00000000 default for horizontal upsampling GKS_K_DOWNSAMPLE_VERTICAL_DEFAULT 0x00000000 default for vertical downsampling GKS_K_DOWNSAMPLE_HORIZONTAL_DEFAULT 0x00000000 default for horizontal downsampling GKS_K_UPSAMPLE_VERTICAL_NEAREST 0x00000001 nearest neighbor for vertical upsampling GKS_K_UPSAMPLE_HORIZONTAL_NEAREST 0x00000100 nearest neighbor for horizontal upsampling GKS_K_DOWNSAMPLE_VERTICAL_NEAREST 0x00010000 nearest neighbor for vertical downsampling GKS_K_DOWNSAMPLE_HORIZONTAL_NEAREST 0x01000000 nearest neighbor for horizontal downsampling GKS_K_UPSAMPLE_VERTICAL_LINEAR 0x00000002 linear for vertical upsampling GKS_K_UPSAMPLE_HORIZONTAL_LINEAR 0x00000200 linear for horizontal upsampling GKS_K_DOWNSAMPLE_VERTICAL_LINEAR 0x00020000 linear for vertical downsampling GKS_K_DOWNSAMPLE_HORIZONTAL_LINEAR 0x02000000 linear for horizontal downsampling GKS_K_UPSAMPLE_VERTICAL_LANCZOS 0x00000003 lanczos for vertical upsampling GKS_K_UPSAMPLE_HORIZONTAL_LANCZOS 0x00000300 lanczos for horizontal upsampling GKS_K_DOWNSAMPLE_VERTICAL_LANCZOS 0x00030000 lanczos for vertical downsampling GKS_K_DOWNSAMPLE_HORIZONTAL_LANCZOS 0x03000000 lanczos for horizontal downsampling

void gr_inqresamplemethod(unsigned int*)

Inquire the resample flag status.

Return

Resample flag

void gr_path(int, double*, double*, const char*)

Draw paths using given vertices and path codes.

The values for

x and y are in world coordinates. n is the number of vertices to use. The codes describe several patch primitives that can be used to create compound paths.
Parameters
• [in] n: The number of points

• [in] x: A pointer to the X coordinates

• [in] y: A pointer to the Y coordinates

• [in] codes: Path codes as a null-terminated string

The following path codes are recognized:

 Code Description x y M, m move x y L, l line x y Q, q quadratic Bezier x1, x2 y1, y2 C, c cubic Bezier x1, x2, x3 y1, y2, y3 A, a arc rx, a1, reserved ry, a2, reserved Z close path S stroke s close path and stroke f close path and fill F close path, fill and stroke

• M, m

Moves the current position to (x, y). The new position is either absolute (M) or relative to the current position (m). The initial position of gr_path is (0, 0).

Example:

double x[2] = {0.5, -0.1};
double y[2] = {0.2, 0.1};
gr_path(2, x, y, "Mm");


The first move command in this example moves the current position to the absolute coordinates (0.5, 0.2). The second move to performs a movement by (-0.1, 0.1) relative to the current position resulting in the point (0.4, 0.3).

• L, l

Draws a line from the current position to the given position (x, y). The end point of the line is either absolute (L) or relative to the current position (l). The current position is set to the end point of the line.

Example:

double x[3] = {0.1, 0.5, 0.0};
double y[3] = {0.1, 0.1, 0.2};
gr_path(3, x, y, "MLlS");


The first line to command draws a straight line from the current position (0.1, 0.1) to the absolute position (0.5, 0.1) resulting in a horizontal line. The second line to command draws a vertical line relative to the current position resulting in the end point (0.5, 0.3).

• Q, q

Draws a quadratic bezier curve from the current position to the end point (x2, y2) using (x1, y1) as the control point. Both points are either absolute (Q) or relative to the current position (q). The current position is set to the end point of the bezier curve.

Example:

double x[5] = {0.1, 0.3, 0.5, 0.2, 0.4};
double y[5] = {0.1, 0.2, 0.1, 0.1, 0.0};
gr_path(5, x, y, "MQqS");


This example will generate two bezier curves whose start and end points are each located at y=0.1. As the control points are horizontally in the middle of each bezier curve with a higher y value both curves are symmetrical and bend slightly upwards in the middle. The current position is set to (0.9, 0.1) at the end.

• C, c

Draws a cubic bezier curve from the current position to the end point (x3, y3) using (x1, y1) and (x2, y2) as the control points. All three points are either absolute (C) or relative to the current position (c). The current position is set to the end point of the bezier curve.

Example:

double x[7] = {0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3};
double y[7] = {0.1, 0.2, 0.0, 0.1, 0.1, -0.1, 0.0};
gr_path(7, x, y, "MCcS");


This example will generate two bezier curves whose start and end points are each located at y=0.1. As the control points are equally spaced along the x-axis and the first is above and the second is below the start and end points this creates a wave-like shape for both bezier curves. The current position is set to (0.8, 0.1) at the end.

• A, a

Draws an elliptical arc starting at the current position. The major axis of the ellipse is aligned with the x-axis and the minor axis is aligned with the y-axis of the plot. rx and ry are the ellipses radii along the major and minor axis. a1 and a2 define the start and end angle of the arc in radians. The current position is set to the end point of the arc. If a2 is greater than a1 the arc is drawn counter-clockwise, otherwise it is drawn clockwise. The a and A commands draw the same arc. The third coordinates of the x and y array are ignored and reserved for future use.

Examples:

double x[4] = {0.1, 0.2, -3.14159 / 2, 0.0};
double y[4] = {0.1, 0.4, 3.14159 / 2, 0.0};
gr_path(4, x, y, "MAS");


This example draws an arc starting at (0.1, 0.1). As the start angle -pi/2 is smaller than the end angle pi/2 the arc is drawn counter-clockwise. In this case the right half of an ellipse with an x radius of 0.2 and a y radius of 0.4 is shown. Therefore the current position is set to (0.1, 0.9) at the end.

double x[4] = {0.1, 0.2, 3.14159 / 2, 0.0};
double y[4] = {0.9, 0.4, -3.14159 / 2, 0.0};
gr_path(4, x, y, "MAS");


This examples draws the same arc as the previous one. The only difference is that the starting point is now at (0.1, 0.9) and the start angle pi/2 is greater than the end angle -pi/2 so that the ellipse arc is drawn clockwise. Therefore the current position is set to (0.1, 0.1) at the end.

• Z

Closes the current path by connecting the current position to the target position of the last move command (m or M) with a straight line. If no move to was performed in this path it connects the current position to (0, 0). When the path is stroked this line will also be drawn.

• S, s

Strokes the path with the current border width and border color (set with gr_setborderwidth and gr_setbordercolorind). In case of s the path is closed beforehand, which is equivalent to ZS.

• F, f

Fills the current path using the even-odd-rule using the current fill color. Filling a path implicitly closes the path. The fill color can be set using gr_setfillcolorind. In case of F the path is also stroked using the current border width and color afterwards.

void gr_setborderwidth(double)

Define the border width of subsequent path output primitives.

Parameters
• [in] width: The border width scale factor

void gr_inqborderwidth(double*)
void gr_setbordercolorind(int)

Define the border color of subsequent path output primitives.

Parameters
• [in] color: The border color index (COLOR < 1256)

void gr_inqbordercolorind(int*)
void gr_selectclipxform(int)
void gr_inqclipxform(int*)
void gr_setprojectiontype(int)

Set the projection type with this flag.

The available options are:

Parameters
• [in] flag: projection type

 GR_PROJECTION_DEFAULT 0 default GR_PROJECTION_ORTHOGRAPHIC 1 orthographic GR_PROJECTION_PERSPECTIVE 2 perspective

void gr_inqprojectiontype(int*)

Return the projection type.

void gr_setperspectiveprojection(double, double, double)

Set the far and near clipping plane for perspective projection and the vertical field ov view

Switches projection type to perspective

Parameters
• near_plane: distance to near clipping plane

• far_plane: distance to far clipping plane

• fov: vertical field of view, input must be between 0 and 180 degrees

void gr_inqperspectiveprojection(double*, double*, double*)

Return the parameters for the perspective projection.

void gr_settransformationparameters(double, double, double, double, double, double, double, double, double)

Method to set the camera position, the upward facing direction and the focus point of the shown volume

Parameters
• camera_pos_x: x component of the cameraposition in world coordinates

• camera_pos_y: y component of the cameraposition in world coordinates

• camera_pos_z: z component of the cameraposition in world coordinates

• up_x: x component of the up vector

• up_y: y component of the up vector

• up_z: z component of the up vector

• focus_point_x: x component of focus-point inside volume

• focus_point_y: y component of focus-point inside volume

• focus_point_z: z component of focus-point inside volume

void gr_inqtransformationparameters(double*, double*, double*, double*, double*, double*, double*, double*, double*)

Return the camera position, up vector and focus point.

void gr_setorthographicprojection(double, double, double, double, double, double)

Set parameters for orthographic transformation

Switches projection type to orthographic

Parameters
• left: xmin of the volume in worldcoordinates

• right: xmax of volume in worldcoordinates

• bottom: ymin of volume in worldcoordinates

• top: ymax of volume in worldcoordinates

• near_plane: distance to near clipping plane

• far_plane: distance to far clipping plane

void gr_inqorthographicprojection(double*, double*, double*, double*, double*, double*)

Return the parameters for the orthographic projection.

void gr_camerainteraction(double, double, double, double)

Rotate the current scene according to a virtual arcball.

This function requires values between 0 (left side or bottom of the drawing area) and 1 (right side or top of the drawing area).

Parameters
• start_mouse_pos_x: x component of the start mouse position

• start_mouse_pos_y: y component of the start mouse position

• end_mouse_pos_x: x component of the end mouse position

• end_mouse_pos_y: y component of the end mouse position

void gr_setwindow3d(double, double, double, double, double, double)

Set the three dimensional window. Only used for perspective and orthographic projection.

Parameters
• xmin: min x-value

• xmax: max x-value

• ymin: min y-value

• ymax: max y-value

• zmin: min z-value

• zmax: max z-value

void gr_inqwindow3d(double*, double*, double*, double*, double*, double*)
void gr_setscalefactors3d(double, double, double)

Set the scale factor for each axis.

The scaling factors must not be zero.

Parameters
• x_axis_scale: factor for scaling the x-axis

• y_axis_scale: factor for scaling the y-axis

• z_axis_scale: factor for scaling the z-axis

void gr_inqscalefactors3d(double*, double*, double*)

Returns the scaling factor for each axis.

void gr_setspace3d(double, double, double, double)

Set the camera for orthographic or perspective projection.

The center of the 3d window is used as the focus point and the camera is positioned relative to it, using camera distance, azimuthal angle and polar angle similar to gr_setspace. This function can be used if the user prefers spherical coordinates to setting the camera position directly, but has reduced functionality in comparison to gr_settransformationparameters, gr_setscalefactors3d, gr_setperspectiveprojection and gr_setorthographicprojection.

Parameters
• phi: azimuthal angle of the spherical coordinates

• theta: polar angle of the spherical coordinates

• fov: vertical field of view(0 or NaN for orthographic projection)

• camera_distance: distance between the camera and the focus point (in arbitrary units, 0 or NaN for the radius of the object’s smallest bounding sphere)

void gr_text3d(double, double, double, char*, int axis)
void gr_inqtext3d(double, double, double, char*, int axis, double*, double*)

Allows you to get the 2d coordinates and transformed coordinates of a text as if displayed by gr_text3d

The first 8 coordinates are pre-transformation coordinates, while the last 8 coordinates are transformed coordinates The first 4 coordinates each are the corners of the bounding box, including ascender and descender space, while the last 4 coordinates are without ascenders and descenders.

Parameters
• [in] x: The base X coordinate

• [in] y: The base Y coordinate

• [in] z: The base z coordinate

• [in] chars: The string to draw

• [in] axis: In which direction the text is drawn (1: YX-plane, 2: XY plane, 3: YZ plane, 4: XZ plane)

• [in] tbx: A double array of 16 elements to write x-coordinates to

• [in] tby: A double array of 16 elements to write y-coordinates to

void gr_settextencoding(int)
void gr_inqtextencoding(int*)
void gr_loadfont(char*, int*)

Load a font file from a given filename.

This function loads a font from a given filename and assigns a font index to it. To use the loaded font call

gr_settextfontprec using the resulting font index and precision 3.
 int font;
gr_settextfontprec(font, 3);

Parameters
• [in] filename: The absolute filename of the font

• [out] font: The font index to use with gr_settextfontprec

The filename can either be an absolute path or a filename like Arial.ttf. Font files are searched in the directories specified by the GKS_FONT_DIRS environment variable and the operating systems default font locations.

As the font file is internally loaded using FreeType, it is required that FreeType support is compiled in and FreeType has to support the given file type. On error the font index is set to -1.

void gr_setcallback(char *(*)(const char*))
void gr_setthreadnumber(int)

Set the number of threads which can run parallel. The default value is the number of threads the cpu has. The only ussage right now is inside gr_cpubasedvolume.

Parameters
• [in] num: number of threads

void gr_setpicturesizeforvolume(int, int)

Set the width and height of the resulting picture. These values are only used for gr_volume and gr_cpubasedvolume. The default values are 1000 for both.

Parameters
• [in] width: width of the resulting image

• [in] height: height of the resulting image

void gr_setvolumebordercalculation(int)
void gr_inqvolumeflags(int*, int*, int*, int*)
void gr_cpubasedvolume(int, int, int, double*, int, double*, double*, double*, double*)

Set the gr_volume border type with this flag. This inflicts how the volume is calculated. When the flag is set to GR_VOLUME_WITH_BORDER the border will be calculated the same as the points inside the volume.

The available options are:

Parameters
• [in] flag: calculation of the gr_volume border

 GR_VOLUME_WITHOUT_BORDER 0 default value GR_VOLUME_WITH_BORDER 1 gr_volume with border

/

void gr_setvolumebordercalculation(int flag) {

check_autoinit;

if (flag == GR_VOLUME_WITHOUT_BORDER || flag == GR_VOLUME_WITH_BORDER)
{

vt.border = flag;

}

else
{
fprintf(stderr, “Invalid gr_volume bordercalculation flag. Possible options are GR_VOLUME_WITHOUT_BORDER, “

”GR_VOLUME_WITH_BORDER n”);

}

if (flag_graphics) gr_writestream(“<setvolumebordercalculation flag="%i"/>n”, flag);

}

/ !

Inquire the parameters which can be set for gr_cpubasedvolume. The size of the resulting image, the way the volumeborder is calculated and the amount of threads which are used.

param[out] border flag which tells how the border is calculated param[out] max_threads number of threads param[out] picture_width width of the resulting image param[out] picture_height height of the resulting image

/

void gr_inqvolumeflags(int border, int *max_threads, int *picture_width, int *picture_height) {

check_autoinit;

border = vt.border; max_threads = vt.max_threads; picture_width = vt.picture_width; picture_height = vt.picture_height;

}

static void draw_volume(const double pixels) {

int i; double dmax; double xmin, ymin, xmax, ymax; int ipixels;

ipixels = (int )gks_malloc(vt.picture_width * vt.picture_height * sizeof(int));

dmax = pixels[0]; for (i = 1; i < vt.picture_width vt.picture_height; i++)

{
if (pixels[i] > dmax)
{

dmax = pixels[i];

}

}

int colormap = (int *)gks_malloc((last_color - first_color + 1) * sizeof(int)); for (i = first_color; i <= last_color; i++)

{

gr_inqcolor(i, colormap + i - first_color);

}

for (i = 0; i < vt.picture_width vt.picture_height; i++)
{
if (pixels[i] >= 0)
{
if (dmax == 0)
{

ipixels[i] = 0;

}

else
{

ipixels[i] = (255u << 24) + colormap[(int)(pixels[i] / dmax (last_color - first_color))];

}

}

}

gr_inqwindow(&xmin, &xmax, &ymin, &ymax); drawimage_calculation(xmin, xmax, ymin, ymax, vt.picture_width, vt.picture_height, ipixels, 0);

free(ipixels); free(colormap);

}

int i, j; double ray_start[3], ray_dir[3], ray_dir_default[3], tmp[3];

/ get the necessary attributes out of the structs */ struct thread_attr ta = (struct thread_attr *)arg; struct ray_casting_attr rc = vt.ray_casting;

int nx = rc->nx, ny = rc->ny, nz = rc->nz; int algorithm = rc->algorithm; double data = rc->data, *pixels = rc->pixels; double dmax_ptr = rc->dmax_ptr, *dmin_ptr = rc->dmin_ptr; double max_val = rc->max_val, *min_val = rc->min_val;

double eps = 1e-8; / precision parameter for comparisons */ double x_spacing = (max_val[0] - min_val[0]) / nx; double y_spacing = (max_val[1] - min_val[1]) / ny; double z_spacing = (max_val[2] - min_val[2]) / nz;

/ transform values into integer */ double min_val_t[3] = {0, 0, 0}; double max_val_t[3] = {nx - 1, ny - 1, nz - 1}; if (vt.border == GR_VOLUME_WITH_BORDER)

{

min_val_t[0] = min_val_t[1] = min_val_t[2] = -0.5; max_val_t[0] = nx - 0.5; max_val_t[1] = ny - 0.5; max_val_t[2] = nz - 0.5;

}

/ the direction of each ray is the same when the projection_type is set to orthographic */ ray_dir_default[0] = (tx.focus_point_x - tx.camera_pos_x); ray_dir_default[1] = (tx.focus_point_y - tx.camera_pos_y); ray_dir_default[2] = (tx.focus_point_z - tx.camera_pos_z);

double f_length = sqrt(ray_dir_default[0] ray_dir_default[0] + ray_dir_default[1] * ray_dir_default[1] +

ray_dir_default[2] ray_dir_default[2]);

ray_dir_default[0] /= f_length; ray_dir_default[1] /= f_length; ray_dir_default[2] /= f_length;

if (gpx.projection_type == GR_PROJECTION_ORTHOGRAPHIC)
{

ray_dir[0] = ray_dir_default[0]; ray_dir[1] = ray_dir_default[1]; ray_dir[2] = ray_dir_default[2];

}

for (i = ta->x_start; i < ta->x_end; i++)
{
for (j = ta->y_start; j < ta->y_end; j++)
{

double color = 0;

/ cast ray */ if (gpx.projection_type == GR_PROJECTION_ORTHOGRAPHIC)

{

double width_steps = (gpx.right - gpx.left) / vt.picture_width; double heigth_steps = (gpx.top - gpx.bottom) / vt.picture_height;

/ uses the pixel mid point */ tmp[0] = gpx.left + (0.5 + i) width_steps; tmp[1] = gpx.bottom + (0.5 + j) heigth_steps; tmp[2] = gpx.near_plane;

/ transform the point into the camera system */ ray_start[0] = tmp[0] tx.s_x - tmp[1] * tx.up_x + tmp[2] * ray_dir[0]; ray_start[1] = tmp[0] tx.s_y - tmp[1] * tx.up_y + tmp[2] * ray_dir[1]; ray_start[2] = tmp[0] tx.s_z - tmp[1] * tx.up_z + tmp[2] * ray_dir[2];

}

else if (gpx.projection_type == GR_PROJECTION_PERSPECTIVE)
{

ray_start[0] = tx.camera_pos_x; ray_start[1] = tx.camera_pos_y; ray_start[2] = tx.camera_pos_z;

/ calculate position on near_plane */ double near_plane[3] = {min(gpx.near_plane, fabs(gpx.near_plane - ray_start[0])),

min(gpx.near_plane, fabs(gpx.near_plane - ray_start[1])), min(gpx.near_plane, fabs(gpx.near_plane - ray_start[2]))};

near_plane[0] = gpx.near_plane / (gpx.far_plane - gpx.near_plane); near_plane[1] = gpx.near_plane / (gpx.far_plane - gpx.near_plane); near_plane[2] = gpx.near_plane / (gpx.far_plane - gpx.near_plane);

double lam = NAN; if (fabs(ray_dir_default[0]) >= eps)

{

lam = fabs((near_plane[0]) / ray_dir_default[0]);

}

if (fabs(ray_dir_default[1]) >= eps)
{

double tmp_lam = fabs((near_plane[1]) / ray_dir_default[1]); if ((lam != lam) || (lam == lam && tmp_lam < lam))

{

lam = tmp_lam;

}

}

if (fabs(ray_dir_default[2]) >= eps)
{

double tmp_lam = fabs((near_plane[2]) / ray_dir_default[2]); if ((lam != lam) || (lam == lam && tmp_lam < lam))

{

lam = tmp_lam;

}

}

/ calculate size of near plane with tan */ double near_plane_size = tan(gpx.fov M_PI / 360.0) *

sqrt(pow(lam ray_dir_default[0], 2) + pow(lam * ray_dir_default[1], 2) +

pow(lam ray_dir_default[2], 2));

/ calculate the position where each ray starts on the near plane */ ray_start[0] = tx.s_x (-near_plane_size + 2 * near_plane_size * (i + 0.5) / vt.picture_width) -

tx.up_x (-near_plane_size + 2 * near_plane_size * (j + 0.5) / vt.picture_height) + ray_start[0] + lam ray_dir_default[0];

ray_start[1] = tx.s_y (-near_plane_size + 2 * near_plane_size * (i + 0.5) / vt.picture_width) -

tx.up_y (-near_plane_size + 2 * near_plane_size * (j + 0.5) / vt.picture_height) + ray_start[1] + lam ray_dir_default[1];

ray_start[2] = tx.s_z (-near_plane_size + 2 * near_plane_size * (i + 0.5) / vt.picture_width) -

tx.up_z (-near_plane_size + 2 * near_plane_size * (j + 0.5) / vt.picture_height) + ray_start[2] + lam ray_dir_default[2];

/ ray_dir depending on point and angle */ ray_dir[0] = ray_start[0] - tx.camera_pos_x; ray_dir[1] = ray_start[1] - tx.camera_pos_y; ray_dir[2] = ray_start[2] - tx.camera_pos_z;

f_length = sqrt(ray_dir[0] ray_dir[0] + ray_dir[1] * ray_dir[1] + ray_dir[2] * ray_dir[2]); ray_dir[0] /= f_length; ray_dir[1] /= f_length; ray_dir[2] /= f_length;

}

/ transform interval same like the original data points */ ray_start[0] =

((ray_start[0] - min_val[0]) / (max_val[0] - min_val[0]) (max_val_t[0] - min_val_t[0])) + min_val_t[0];

ray_start[1] =

((ray_start[1] - min_val[1]) / (max_val[1] - min_val[1]) (max_val_t[1] - min_val_t[1])) + min_val_t[1];

ray_start[2] =

((ray_start[2] - min_val[2]) / (max_val[2] - min_val[2]) (max_val_t[2] - min_val_t[2])) + min_val_t[2];

double lambda[3] = {

0,

};

/ when or does the ray hits parts of the volume */ / calculate the lambda for each direction and take maximum of these three values */ if (fabs(ray_dir[0]) >= eps)

{

double dirfrac = 1.0 / ray_dir[0]; lambda[0] = min((min_val_t[0] - ray_start[0]) dirfrac, (max_val_t[0] - ray_start[0]) * dirfrac);

}

if (fabs(ray_dir[1]) >= eps)
{

double dirfrac = 1.0 / ray_dir[1]; lambda[1] = min((min_val_t[1] - ray_start[1]) dirfrac, (max_val_t[1] - ray_start[1]) * dirfrac);

}

if (fabs(ray_dir[2]) >= eps)
{

double dirfrac = 1.0 / ray_dir[2]; lambda[2] = min((min_val_t[2] - ray_start[2]) dirfrac, (max_val_t[2] - ray_start[2]) * dirfrac);

}

double max_lambda = max(lambda[0], max(lambda[1], lambda[2]));

/ point where the ray enters the volume when possible */ if (min_val_t[0] - (ray_start[0] + max_lambda ray_dir[0]) > eps ||

(ray_start[0] + max_lambda ray_dir[0]) - max_val_t[0] > eps)

{

pixels[i + j vt.picture_width] = -1; continue;

}

if (min_val_t[1] - (ray_start[1] + max_lambda ray_dir[1]) > eps ||

(ray_start[1] + max_lambda ray_dir[1]) - max_val_t[1] > eps)

{

pixels[i + j vt.picture_width] = -1; continue;

}

if (min_val_t[2] - (ray_start[2] + max_lambda ray_dir[2]) > eps ||

(ray_start[2] + max_lambda ray_dir[2]) - max_val_t[2] > eps)

{

pixels[i + j vt.picture_width] = -1; continue;

}

ray_start[0] += max_lambda ray_dir[0]; ray_start[1] += max_lambda ray_dir[1]; ray_start[2] += max_lambda ray_dir[2];

/ influence of the voxels which are passed by each ray */ double start[1] = {NAN}; while (1)

{

double voxel_val, voxel_influ; double ray_length; double end[1]; double x_dist, y_dist, z_dist;

/ end point */ if (ray_dir[0] < 0)

{

lambda[0] = (max(RAYCASTING_FLOOR(ray_start[0]), min_val_t[0]) - ray_start[0]) / ray_dir[0];

}

else
{

lambda[0] = (min(RAYCASTING_CEIL(ray_start[0]), max_val_t[0]) - ray_start[0]) / ray_dir[0];

}

if (ray_dir[1] < 0)
{

lambda[1] = (max(RAYCASTING_FLOOR(ray_start[1]), min_val_t[1]) - ray_start[1]) / ray_dir[1];

}

else
{

lambda[1] = (min(RAYCASTING_CEIL(ray_start[1]), max_val_t[1]) - ray_start[1]) / ray_dir[1];

}

if (ray_dir[2] < 0)
{

lambda[2] = (max(RAYCASTING_FLOOR(ray_start[2]), min_val_t[2]) - ray_start[2]) / ray_dir[2];

}

else
{

lambda[2] = (min(RAYCASTING_CEIL(ray_start[2]), max_val_t[2]) - ray_start[2]) / ray_dir[2];

}

double lambda_min = lambda[0]; if ((fabs(lambda_min) > fabs(lambda[1]) || lambda_min != lambda_min) && lambda[1] == lambda[1])

lambda_min = lambda[1];

if ((fabs(lambda_min) > fabs(lambda[2]) || lambda_min != lambda_min) && lambda[2] == lambda[2])

lambda_min = lambda[2];

double ray_end[3] = {ray_start[0] + lambda_min ray_dir[0], ray_start[1] + lambda_min * ray_dir[1],

ray_start[2] + lambda_min ray_dir[2]};

/ identify voxel */ int x_0 = 0, y_0 = 0, z_0 = 0; int x_1 = 0, y_1 = 0, z_1 = 0;

if (ray_dir[0] >= -eps)
{
if (fabs(ray_start[0]) > eps)
{

x_0 = min(nx - 1, (ray_start[0] - fmod(ray_start[0], 1)));

}

x_1 = x_0; if (ray_end[0] < nx - 1 + eps)

{

x_1 = (int)min(nx - 1, max(0, RAYCASTING_CEIL(ray_start[0])));

}

}

else if (ray_dir[0] < eps)
{
if (fabs(ray_start[0]) > eps)
{

x_0 = min(nx - 1, max(0, (ray_start[0] - fmod(ray_start[0] - ceil(ray_start[0]), 1))));

}

x_1 = x_0; if (ray_end[0] >= -eps)

{

x_1 = (int)min(nx - 1, max(0, RAYCASTING_FLOOR(ray_start[0])));

}

}

if (ray_dir[1] >= -eps)
{
if (fabs(ray_start[1]) > eps)
{

y_0 = min(ny - 1, (ray_start[1] - fmod(ray_start[1], 1)));

}

y_1 = y_0; if (ray_end[1] < ny - 1 + eps)

{

y_1 = (int)min(ny - 1, max(0, RAYCASTING_CEIL(ray_start[1])));

}

}

else if (ray_dir[1] < eps)
{
if (fabs(ray_start[1]) > eps)
{

y_0 = min(ny - 1, max(0, (ray_start[1] - fmod(ray_start[1] - ceil(ray_start[1]), 1))));

}

y_1 = y_0; if (ray_end[1] >= -eps)

{

y_1 = (int)min(ny - 1, max(0, RAYCASTING_FLOOR(ray_start[1])));

}

}

if (ray_dir[2] >= -eps)
{
if (fabs(ray_start[2]) > eps)
{

z_0 = min(nz - 1, (ray_start[2] - fmod(ray_start[2], 1)));

}

z_1 = z_0; if (ray_end[2] < nz - 1 + eps)

{

z_1 = (int)min(nz - 1, max(0, RAYCASTING_CEIL(ray_start[2])));

}

}

else if (ray_dir[2] < eps)
{
if (fabs(ray_start[2]) > eps)
{

z_0 = min(nz - 1, max(0, (ray_start[2] - fmod(ray_start[2] - ceil(ray_start[2]), 1))));

}

z_1 = z_0; if (ray_end[2] >= -eps)

{

z_1 = (int)min(nz - 1, max(0, RAYCASTING_FLOOR(ray_start[2])));

}

}

int k, repeat = 1; double bilinear_ptr[1]; if ( start != *start)

{

repeat = 0;

}

double dist_copy[3] = {NAN, NAN, NAN}; for (k = repeat; k < 2; k++)

{

double ray_position[3] = {ray_end[0], ray_end[1], ray_end[2]}; if (k == 0)

{

ray_position[0] = ray_start[0]; ray_position[1] = ray_start[1]; ray_position[2] = ray_start[2]; bilinear_ptr[0] = start;

}

else
{

bilinear_ptr[0] = end;

}

if (ray_dir[0] >= -eps)
{

x_dist = fabs(min(nx, ray_position[0]) - x_0); if (ray_position[0] <= 0)

{

x_dist = fabs(ray_position[0] - min_val_t[0]);

}

}

else
{

x_dist = fabs(max(ray_position[0], -1) - x_0); if (ray_position[0] >= nx - 1)

{

x_dist = fabs(ray_position[0] - max_val_t[0]);

}

}

if (ray_dir[1] >= -eps)
{

y_dist = fabs(min(ny, ray_position[1]) - y_0); if (ray_position[1] <= 0)

{

y_dist = fabs(ray_position[1] - min_val_t[1]);

}

}

else
{

y_dist = fabs(max(ray_position[1], -1) - y_0); if (ray_position[1] >= ny - 1)

{

y_dist = fabs(ray_position[1] - max_val_t[1]);

}

}

if (ray_dir[2] >= -eps)
{

z_dist = fabs(min(nz, ray_position[2]) - z_0); if (ray_position[2] <= 0)

{

z_dist = fabs(ray_position[2] - min_val_t[2]);

}

}

else
{

z_dist = fabs(max(ray_position[2], -1) - z_0); if (ray_position[2] >= nz - 1)

{

z_dist = fabs(ray_position[2] - max_val_t[2]);

}

}

if (ray_position[0] > nx - 1 + sign(ray_dir[0]) eps || ray_position[0] < sign(ray_dir[0]) * eps)
{

x_dist = 2;

}

if (ray_position[1] > ny - 1 + sign(ray_dir[1]) eps || ray_position[1] < sign(ray_dir[1]) * eps)
{

y_dist = 2;

}

if (ray_position[2] > nz - 1 + sign(ray_dir[2]) eps || ray_position[2] < sign(ray_dir[2]) * eps)
{

z_dist = 2;

}

if ((fabs(x_dist - 0) <= eps || fabs(x_dist - 1) <= eps) && fabs(ray_dir[0]) > eps)
{

int x_tmp = x_0; if (fabs(x_dist - 1) <= eps)

{

x_tmp = x_1;

}

bilinear_interpolation(data[x_tmp + y_0 nx + z_0 * (nx * ny)],

data[x_tmp + y_1 nx + z_0 * (nx * ny)], data[x_tmp + y_0 nx + z_1 * (nx * ny)], data[x_tmp + y_1 nx + z_1 * (nx * ny)], y_dist, z_dist, bilinear_ptr[0]);

if (dist_copy[0] == dist_copy[0])
{
bilinear_interpolation(

data[x_tmp + y_0 nx + z_0 * (nx * ny)], data[x_tmp + y_1 * nx + z_0 * (nx * ny)], data[x_tmp + y_0 nx + z_1 * (nx * ny)], data[x_tmp + y_1 * nx + z_1 * (nx * ny)], dist_copy[1], dist_copy[2], start);

}

}

else if ((fabs(y_dist - 0) <= eps || fabs(y_dist - 1) <= eps) && fabs(ray_dir[1]) > eps)
{

int y_tmp = y_0; if (fabs(y_dist - 1) <= eps)

{

y_tmp = y_1;

}

bilinear_interpolation(data[x_0 + y_tmp nx + z_0 * (nx * ny)],

data[x_1 + y_tmp nx + z_0 * (nx * ny)], data[x_0 + y_tmp nx + z_1 * (nx * ny)], data[x_1 + y_tmp nx + z_1 * (nx * ny)], x_dist, z_dist, bilinear_ptr[0]);

if (dist_copy[0] == dist_copy[0])
{
bilinear_interpolation(

data[x_0 + y_tmp nx + z_0 * (nx * ny)], data[x_1 + y_tmp * nx + z_0 * (nx * ny)], data[x_0 + y_tmp nx + z_1 * (nx * ny)], data[x_1 + y_tmp * nx + z_1 * (nx * ny)], dist_copy[0], dist_copy[2], start);

}

}

else if ((fabs(z_dist - 0) <= eps || fabs(z_dist - 1) <= eps) && fabs(ray_dir[2]) > eps)
{

int z_tmp = z_0; if (fabs(z_dist - 1) <= eps)

{

z_tmp = z_1;

}

bilinear_interpolation(data[x_0 + y_0 nx + z_tmp * (nx * ny)],

data[x_1 + y_0 nx + z_tmp * (nx * ny)], data[x_0 + y_1 nx + z_tmp * (nx * ny)], data[x_1 + y_1 nx + z_tmp * (nx * ny)], x_dist, y_dist, bilinear_ptr[0]);

if (dist_copy[0] == dist_copy[0])
{
bilinear_interpolation(

data[x_0 + y_0 nx + z_tmp * (nx * ny)], data[x_1 + y_0 * nx + z_tmp * (nx * ny)], data[x_0 + y_1 nx + z_tmp * (nx * ny)], data[x_1 + y_1 * nx + z_tmp * (nx * ny)], dist_copy[0], dist_copy[1], start);

}

}

if ( start != *start)
{

dist_copy[0] = x_dist; dist_copy[1] = y_dist; dist_copy[2] = z_dist;

}

}

/ set the values */ ray_length = sqrt(pow((ray_end[0] - ray_start[0]) x_spacing, 2) +

pow((ray_end[1] - ray_start[1]) y_spacing, 2) + pow((ray_end[2] - ray_start[2]) z_spacing, 2));

voxel_val = ( start + *end) / 2; voxel_influ = voxel_val ray_length;

if (algorithm == 0)
{

/ emission */ color += voxel_influ; if (rc->dmax_ptr != NULL && color >= dmax_ptr) break;

}

else if (algorithm == 1)
{

/ absorption */ color += voxel_influ; if (rc->dmin_ptr != NULL && color <= dmin_ptr) break;

}

else
{

/ MIP */ if ( start > color)

{

color = start;

}

if ( end > color)
{

color = end;

}

if (rc->dmax_ptr != NULL && color >= dmax_ptr) break;

}

ray_start[0] = ray_end[0]; ray_start[1] = ray_end[1]; ray_start[2] = ray_end[2];

/ can reuse end value */

start = *end;

if (fabs(ray_start[0] - max_val_t[0]) <= eps || fabs(ray_start[1] - max_val_t[1]) <= eps ||

fabs(ray_start[2] - max_val_t[2]) <= eps)

{

break;

}

if (fabs(ray_start[0] - min_val_t[0]) <= eps || fabs(ray_start[1] - min_val_t[1]) <= eps ||

fabs(ray_start[2] - min_val_t[2]) <= eps)

{

break;

}

}

if (algorithm == 1)
{

/ absorption */ color = exp(-color);

}

if (rc->dmax_ptr != NULL && color > dmax_ptr) color = *dmax_ptr; if (rc->dmin_ptr != NULL && color < dmin_ptr) color = *dmin_ptr; pixels[i + j vt.picture_width] = color;

}

}

}

/ !

Draw volume data with raycasting using the given algorithm and apply the current GR colormap.

param[in] nx number of points in x-direction param[in] ny number of points in y-direction param[in] nz number of points in z-direction param[in] data an array of shape nx * ny * nz containing the intensities for each point param[in] algorithm the algorithm to reduce the volume data param[in,out] dmin_ptr The variable this parameter points at will be used as minimum data value when applying the

colormap. If it is negative, the variable will be set to the actual occuring minimum and that value will be used instead. If dmin_ptr is NULL, it will be ignored.

param[in,out] dmax_ptr The variable this parameter points at will be used as maximum data value when applying the

colormap. If it is negative, the variable will be set to the actual occuring maximum and that value will be used instead. If dmax_ptr is NULL, it will be ignored.

param[in] min_val array with the minimum coordinates of the volumedata param[in] max_val array with the maximum coordinates of the volumedata

struct vertex_t
double x
double y