File libluminate/render.c

RCS Header

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 _REENTRANT 1

#define ORBIT2 1

#define IMLIB2_EXISTS 1

#define DPRINTF( fmt, args... )

#define __FUNCT__ "pseudocolor"

#define __FUNCT__ "pseudoternarycolor"

#define __FUNCT__ "pseudoternarysquarecolor"

#define __FUNCT__ "pseudohueintcolor"

#define __FUNCT__ "pseudoshearcolor"

#define __FUNCT__ "render_scale_2d"

#define __FUNCT__ "render_composition_path"

#define __FUNCT__ "render_rgb_local_2d"

#define __FUNCT__ "render_rgb_local_3d"


Global Function render_composition_path()

Render a composition path, such as a diffusion path or phase diagram, onto an IDisplay image.

int render_composition_path ( IDisplay Disp, PetscScalar* comp_array, int gridpoints, int num_fields, field_plot_type fieldtype, PetscScalar* scale, PetscScalar red, PetscScalar green, PetscScalar blue, PetscScalar alpha )

int render_composition_path
Returns zero or an error code.
IDisplay Disp
IDisplay object into which to draw the path.
PetscScalar* comp_array
 
int gridpoints
Number of gridpoints in the composition array.
int num_fields
Total number of fields in the composition array.
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.
PetscScalar red
Red color for composition path.
PetscScalar green
Green color for composition path.
PetscScalar blue
Blue color for composition path.
PetscScalar alpha
Alpha channel for composition path.
PetscScalar comp_array Array of compositions for drawing.


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 ( IDisplay Disp, 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 transform, IDisplay SDisp, PetscScalar dpred, PetscScalar dpgreen, PetscScalar dpblue, PetscScalar dpalpha )

int render_rgb_local_2d
Returns zero or an error code.
IDisplay Disp
Display object holding the RGB buffer and its characteristics.
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.
int transform
Transformation flags.
IDisplay SDisp
Display object in which to draw the diffusion path (optional, ignored if NULL).
PetscScalar dpred
Red color for diffusion path points (0-1).
PetscScalar dpgreen
Green color for diffusion path points (0-1).
PetscScalar dpblue
Blue color for diffusion path points (0-1).
PetscScalar dpalpha
Alpha channel for diffusion path points (0-1).

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 ( IDisplay Disp, ISurface Surf, PetscScalar* eye, PetscScalar* dir, PetscScalar* right )

int render_rgb_local_3d
Returns zero or an error code.
IDisplay Disp
Display object holding the RGB buffer and its characteristics.
ISurface Surf
ISurface object containing triangles to render using imlib2 backend.
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 ( IDisplay Disp, field_plot_type fieldtype, int symmetry )

int render_scale_2d
It returns zero or an error code.
IDisplay Disp
Display object into which to draw the scale.
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.

Local Function pseudoternarysquarecolor()

This little function converts two composition values into an rgb color, with blue, red, green and yellow indicating the corners.

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

PetscScalar A
First ternary composition.
PetscScalar B
Second ternary composition.
PetscScalar* scale
Array: minimum and maximum first and second compositions for scaling.
guchar* pixel
Address in rgb buffer where this pixel should be painted.