QMG logo

Graphics in QMG

QMG can display breps, simplicial complexes, and PDE solutions (the latter in Matlab only) in color. Three-dimensional objects in QMG are currently rendered with VRML or Matlab.

Colors in QMG

The routines for displaying breps examine the value of the color property of the brep's faces. The value of this property should be a 4-tuple of the form (r g b a); where each of r, g, b, a is a decimal number between 0 and 1. (Note: the parentheses are part of the syntax.)

The numbers r, g, b stand for red, green and blue and are the amount of that color present in the face. For instance, r=1, g=0, b=0 is pure red, whereas r=1, g= 1, b=0 is yellow.

The parameter a is sometimes called alpha and is the degree of opacity. Thus, a=1 means the face is completely opaque and a=0 means the face is completely transparent. Somewhere in between 0 and 1 means the face is partially transparent.

Not all the graphics engines support transparency, so you may find that modifying this parameter strictly between 0 and 1 does not yield the desired result. It is guaranteed, however, that a=0 will yield a completely transparent (invisible) face for any graphics engine and a=1 will yield a completely opaque face. Making an exterior face invisible is useful for revealing internal boundaries or completely interior holes.

The graphics routines are as follows.

gmrndcolor (Matlab and Tcl)

Matlab: newbrep=gmrndcolor(brep {, dim});
Tcl/Tk: gmset newbrep [gmrndcolor brep {dim}]
This routine produces a new brep that is the same as the old brep, except that all faces of dimension dim are colored according to an ordering of 26 colors. (The ordering is randomized in Matlab and deterministic in Tcl.) Like all of the QMG routines, this one does not change its calling argument and therefore is useless without a return variable.

The dim argument is optional; It defaults to the embedded dimension of the brep minus 1, or the intrinsic dimension, whichever is smaller. The function does not alter the color of a face that is already has a color property assigned to it.

The gmshowcolor routine is useful for displaying the colors assigned by gmrndcolor.

gmviz (Matlab & Tcl/Tk)

Matlab: gmviz(obj {, colorspec {, dim}});
Tcl/Tk: gmviz obj {colorspec {dim}}
This routine displays a brep or simplicial complex. The display is controlled by gmvizgui.

The arguments determine which dimension or dimensions of object to display. For instance, a third argument of 1 indicates that 1-dimensional faces (the edges) of the brep or simplicial complex should be displayed. The third argument can also be a vector (a list in Tcl/Tk) containing several dimensions of the object to plot at once. The default for the third argument is min(d−1,k) where d is the embedded dimension and k is the intrinsic dimension.

The second argument is the color to use. There must be one color per dimension; in other words, the second and third arguments to gmviz are in correspondence. For example, in Matlab, the call

gmviz(b, 'rw', [1, 2])
will render the 1- and 2-dimensional faces of b (edges and facets). The edges will be colored red and the facets will be colored white. The equivalent in Tcl/Tk is:
gmviz $b {red white} {1 2}

As mentioned above, the second argument is one or more colors, in correspondence with the dimensions. For a brep, the color specified in the gmviz call is overridden by the property-value pair color assigned to the faces. (No such option exists for simplicial complexes since individual simplices do not have property-value pairs.) The default color is obtained from the gmvizgui control panel.

In Matlab, there are two ways to specify color to the gmviz command. A color can either be a one-character string y, m, c, r, g, b, w, k or i standing for yellow, magenta, cyan, red, green, blue, white, black and invisible. Several such colors (one for each dimension) are concatenated together into a string as in the above example.

A color in matlab can also be specified as a matrix with four entries per row; each row is an r, g, b, a encoding as described above. The number of rows is in correspondence to the number of dimensions specified in the third argument. In Tcl/Tk, a color can be any valid X11 color name such as "green". It can also be a four-tuple of numbers.

An alternative calling format for these routines is:

Matlab: gmviz(pair {, colorspec {, dim}});
Tcl/Tk: gmviz pair {colorspec {dim}}
where pair is a mesh-brep pair (2-element cell-array in Matlab, 2-element list in Tcl/Tk). In this calling format, the mesh is displayed using colors inherited from the color values of the faces of the brep. The mesh should belong to the brep.

QMG 2.0 supports two different graphics engine types, internal and external. For Matlab, “internal” means a usual Matlab graphics window. For Tcl/Tk, “internal” means a Tk canvas object. The Matlab internal engine can plot in both two and three dimensions. The Tcl/Tk internal engine is for 2-dimensional objects only.

QMG 2.0 supports one external rendering format, VRML 1.0. When external rendering is requested, gmviz will write the objected to be rendered to a file in VRML format. For information about VRML, see the VRML repository. The software supports automatic notification of Netscape Communicator (or Netscape Navigator) in both Unix and Windows. “Automatic notification” means that gmviz or gmplot will cause the Netscape browser to load the VRML image as soon as the data has written to the file in VRML format. To use notification, the Netscape browser must running on your workstation (as a separate process) at the time the gmviz or gmplot statement is executed. The browser must have a VRML plug-in viewer installed. You control automatic notification with buttons in in the GUI created by gmvizgui.

You can also select the file name to hold the VRML file with the gmvizgui control panel. The default is test.wrl. Always choose a file whose suffix is .wrl. You can also select whether that file is opened in replace-mode or append-mode. Opening the file in append mode means that each successive gmviz statement will each its VRML at the end of the file, so that several different objects can appear at once in the browser.

For Windows only, the software also supports automatic notification of Microsoft Internet Explorer.

The notification is accomplished internally via gm_url in Tcl/Tk or the built-in command web in Matlab. This routine notifies Netscape or IE to load the file using the DDE protocol under Windows. Under Unix, gm_url uses Netscape Navigator's remote control feature for automatic notification.

The rendering engines (both external and internal) support "thickening" options. Thickening a vertex means displaying it as a disk or sphere instead of a point. Thickening an edge means displaying it as a fat line or pipe instead of a segment. Thickening a vertex makes it a disk or ball.

Setting the thickness in a VRML plot of either vertices or lines to anything greater than zero increases both the size of the VRML file and the time required ton render the object. This is because vertices of width greater than 0 are plotted as individual spheres, whereas 0-width vertices are plotted as a point cloud. Similarly, edges of width 0 are rendered all together as an indexed line set in VRML, whereas edges of positive width are rendered individually as cylinders.

When gmviz in Matlab displays a 2D object, it provides six control buttons as follows. Zoom In and Zoom Out zoom in or out on the current center of the object. Up, Down, Left, and Right move your viewpoint on the object.

When gmviz in Matlab displays a 3D object, the buttons Up, Down, Left and Right change your viewpoint as if you are sitting on the surface of a circumscribing sphere around the object.

gmvizgui

Most of these properties are controlled by a panel put up by the function gmvizgui on your screen. Changes made to a setting in this GUI do not affect the current plot; instead, changes take effect for the next plot. After the GUI is closed, its last settings stay in force. Do not start two different gmvizgui windows because they will get out of sync.

This panel controls default colors, choice of renderer, file names (in the case of VRML rendering), and thickness of segments and points.

It also controls the number of bezier subdivisions. When plotting a brep with curved boundaries, the rendering routine first converts the curve into a sequence of straight edges or flat triangles. You can control how many subdivisions are made for this purpose. More subdivisions gives a more accurate rendering but at the cost of greater computation time during rendering.

To try these features out, you can use the interactive script testviz by typing testviz in matlab or source $qmg_library2/testviz.tcl in Tcl/Tk.

Customizing graphics

Graphics in Tcl/Tk and Matlab are both implemented in the scripting language, and therefore are available for easy customization. The only part of the graphics routines coded in C++ is gm_vizp. This routine takes as arguments a brep or simplicial complex and several other parameters and returns a list of points, edges, or triangles ready to be plotted.

gmplot (Matlab only)

The gmplot routine displays a color picture of a 2D or surface 3D finite element solution. It is available only in Matlab. Its calling sequence is:
gmplot(mesh, u {, solnrange {, cmap}});
where mesh is the simplicial complex used for the finite element method, and u is the solution vector. The simplicial complex must have intrinsic dimension 2, and can have embedded dimension of either 2 or 3. The argument u is the value at each node of the simplicial complex that you want plotted. Thus, field should be a zba column vector with real-number entries whose number of entries is equal to the number of nodes in the simplicial complex. This is the form of the return variable from gmfem. But you can also use this function to show, for instance, the difference between two fem solutions.

In the case of 3D FEM solutions, you first have to restrict the mesh to the boundary elements with the gmboundary function. Then you have to restrict the FEM solution u to the subset of nodes in the new simplicial complex by subscripting the full FEM solution with the index-source vector returned by gmboundary. There are examples of this technique in the test cases.

The routine defaults to the jet colormap. The third argument is an optional 2-vector with lower and upper bounds on u. These bounds default to the min and max values of the vector u. Specifying the third argument explicitly is useful when you are making several different plots for which you want the same absolute color scale.

Routine gmplot uses interpolated colors on each triangle in the simplicial complex. However, it does not use the interpolated-color feature that is built in to Matlab (I found that earlier versions of interpolated colors did not work on my color printer. I don't know if this has been fixed in the more recent Matlab releases). Instead, it divides each triangle into nine smaller triangles and uses flat colors (that are linearly interpolated by the gmplot program) on each of the subtriangles. Thus, the triangles you see with gmplot are subtriangles of the actual triangles used in the finite element solver.

The matlab command colorbar is useful in conjunction with the gmplot routine.


This documentation is written by Stephen A. Vavasis and is copyright ©1999 by Cornell University. Permission to reproduce this documentation is granted provided this notice remains attached. There is no warranty of any kind on this software or its documentation. See the accompanying file 'copyright' for a full statement of the copyright.

Stephen A. Vavasis, Computer Science Department, Cornell University, Ithaca, NY 14853, vavasis@cs.cornell.edu