File render.c

RCS Header: /cvsroot/petscgraphics/render.c,v 1.15 2004/11/30 14:35:54 hazelsct Exp

This file contains the rendering code for Illuminator, which renders 2-D or 3-D data into an RGB(A) unsigned char array (using perspective in 3-D).


Included Files


Preprocessor definitions

#define DPRINTF( fmt, args... )

#define __FUNCT__ "pseudocolor"

#define __FUNCT__ "pseudoternarycolor"

#define __FUNCT__ "pseudohueintcolor"

#define __FUNCT__ "pseudoshearcolor"

#define __FUNCT__ "render_scale_2d"

#define __FUNCT__ "render_rgb_local_2d"

#define __FUNCT__ "render_rgb_local_3d"


Global Function render_rgb_local_2d()

Render data from global_array into local part of an RGB buffer. When running in parallel, these local buffers should be collected and layered to produce the full image.

int render_rgb_local_2d ( guchar* rgb, int rwidth, int rheight, int rowskip, int bytes_per_pixel, PetscScalar* global_array, int num_fields, int display_field, field_plot_type fieldtype, PetscScalar* scale, int nx, int ny, int xs, int ys, int xm, int ym )

int render_rgb_local_2d
Returns zero or an error code.
guchar* rgb
RGB buffer, or location in the RGB buffer, in which to render.
int rwidth
Total width of the section of the RGB buffer to draw.
int rheight
Total height of the section of the RGB buffer to draw.
int rowskip
Total width of the RGB buffer.
int bytes_per_pixel
Number of bytes per pixel in this RGB buffer (typically 3 or 4).
PetscScalar* global_array
Local array of global vector data to render.
int num_fields
Number of field variables in the array.
int display_field
The (first) field we are rendering now.
field_plot_type fieldtype
The type of this field.
PetscScalar* scale
Array of minimum and maximum values to pass to the various pseudocolor functions; if NULL, call auto_scale to determine those values.
int nx
Width of the array.
int ny
Height of the array.
int xs
Starting x-coordinate of the local part of the global vector.
int ys
Starting y-coordinate of the local part of the global vector.
int xm
Width of the local part of the global vector.
int ym
Height of the local part of the global vector.

Global Function render_rgb_local_3d()

Render triangle data into an RGB buffer. When called in parallel, the resulting images should be layered to give the complete picture. Zooming is done by adjusting the ratio of the dir vector to the right vector.

The coordinate transformation is pretty simple. A point p in space is transformed to x, y on the screen by representing it as:

p = i + a d + ax r + ay u,
where i is the observer's point (passed in as eye), d is the direction of observation (passed in as dir), r is the rightward direction to the observer (passed in as right), and u is the upward direction to the observer which is given the direction of the cross product of d and r and the magnitude of r.

This system can easily be solved for x and y by first making it into a matrix equation:

(d r u) (a, ax, ay) = p - i.
Calling the matrix M the inverse of the matrix on the left side gives the result:
a= M00 (px-ix) + M01 (py-iy) + M02 (pz-iz),
x= [M10 (px-ix) + M11 (py-iy) + M12 (pz-iz)] / a,
y= [M00 (px-ix) + M01 (py-iy) + M02 (pz-iz)] / a.

The triple product of the vector from the light source to the triangle centroid and the two vectors making up the triangle edges determines the cosine of the angle made by the triangle normal and the incident light, whose absolute value is used here to shade the triangle. At this point, the light source is taken as the observer location at "eye", but that can easily be modified to use one or more independent light sources.

int render_rgb_local_3d ( guchar* rgb, int rwidth, int rheight, int bytes_per_pixel, int num_triangles, PetscScalar* vertices, PetscScalar* eye, PetscScalar* dir, PetscScalar* right )

int render_rgb_local_3d
Returns zero or an error code.
guchar* rgb
RGB buffer in which to render.
int rwidth
Total width of the RGB buffer.
int rheight
Total height of the RGB buffer.
int bytes_per_pixel
Number of bytes per pixel in this RGB buffer (typically 3 or 4).
int num_triangles
Number of triangles to render.
PetscScalar* vertices
Table of coordinates (x1,y1,z1, x2,y2,z2, x3,y3,z3) and colors (RGBA 0-1) making thirteen values per triangle.
PetscScalar* eye
Point from where we're looking (x,y,z).
PetscScalar* dir
Direction we're looking (x,y,z).
PetscScalar* right
Rightward direction in physical space (x,y,z).

Global Function render_scale_2d()

This draws a little rwidth x rheight image depicting the scale of a field variable.

int render_scale_2d ( guchar* rgb, int rwidth, int rheight, int bytes_per_pixel, field_plot_type fieldtype, int symmetry )

int render_scale_2d
It returns zero or an error code.
guchar* rgb
Image to draw into.
int rwidth
Intended width of the image.
int rheight
Intended height of the image.
int bytes_per_pixel
Number of bytes per pixel in the image.
field_plot_type fieldtype
Type of plot.
int symmetry
Symmetry order for vector scale image.

Local Function pseudocolor()

This little function converts a scalar value into an rgb color from red to blue.

static inline void pseudocolor ( PetscScalar val, PetscScalar* scale, guchar* pixel )

PetscScalar val
Value to convert.
PetscScalar* scale
Array with minimum and maximum values in which to scale val.
guchar* pixel
Address in rgb buffer where this pixel should be painted.

Local Function pseudohueintcolor()

This little function converts a vector into an rgb color with hue indicating direction (green, yellow, red, blue at 0, 90, 180, 270 degrees) and intensity indicating magnitude relative to reference magnitude in scale[1].

static inline void pseudohueintcolor ( PetscScalar vx, PetscScalar vy, PetscScalar* scale, guchar* pixel )

PetscScalar vx
Vector's x-component.
PetscScalar vy
Vector's y-component.
PetscScalar* scale
Array whose second entry has the reference magnitude.
guchar* pixel
Address in rgb buffer where this pixel should be painted.

Local Function pseudoshearcolor()

This little function converts a shear tensor (symmetric, diagonals sum to zero) into an rgb color with hue indicating direction of the tensile stress (red, yellow, green, cyan, blue, magenta at 0, 30, 60, 90, 120, 150 degrees respectively; 180 is equivalent to zero for stress) and intensity indicating magnitude relative to reference magnitude in scale[0].

static inline void pseudoshearcolor ( PetscScalar gxx, PetscScalar gxy, PetscScalar* scale, guchar* pixel )

PetscScalar gxx
Tensor's xx-component.
PetscScalar gxy
Tensor's xy-component.
PetscScalar* scale
Array whose first entry has the reference magnitude.
guchar* pixel
Address in rgb buffer where this pixel should be painted.

Local Function pseudoternarycolor()

This little function converts two ternary fractions into an rgb color, with yellow, cyan and magenta indicating the corners.

static inline void pseudoternarycolor ( PetscScalar A, PetscScalar B, PetscScalar* scale, guchar* pixel )

PetscScalar A
First ternary fraction.
PetscScalar B
Second ternary fraction.
PetscScalar* scale
Array first and second ternary fractions of each of the three corner values for scaling.
guchar* pixel
Address in rgb buffer where this pixel should be painted.