next up previous contents
Next: Molecule objects Up: Function and Class Previous: Utility objects

Display objects

 

The following objects are used mainly for the purpose of displaying images to the screen. Items which have a specific section listed for them are explained in detail in that section.

  
Table 6.2: VMD display objects.

ColorList

 

Description

Contains a list of all the items which have an assigned color, and the list of all the different color categories which exist. VMD uses a colormap made of 16 base colors (plus black), and a colorscale made of 32 colors in user-definable gradient (e.g., red-green-blue, or red-white-blue). Color categories are used to contain the names of items which are related and which may have their colors changed; an example of a color category is `Axes', which contains the colors for the `X', `Y', and `Z' axes. The categories contain just a list of names and the associated colors assigned to these names (an integer, from 0 ... 16). Other objects in VMD which are derived from ColorUser can add new color categories (or can query if one of a specific name already exists), and can add new names to an existing color category. The colors assigned to the named items in each category can be changed via the Color menu, or through the color text command. Once a category is created by some ColorUser object (or, if it already exists, has been obtained by the object from ColorList ), the ColorUser can use the category to retrieve the proper color to use for whatever purpose it needs it (i.e., creating the object's display list if it is a Displayable ).

Constructors

Enumerations, lists or character name arrays

There are three different ways to set the colorscale:

There are sixteen colors in the colormap, along with black, for seventeen total colors. They are: blue, red, grey, orange, yellow, tan, silver, green, white pink, cyan, purple, lime, mauve, ochre, iceblue, and black.

Internal data structures

Method of use

VMD contains one global instance of this class, colors. It is used by all objects derived from ColorUser , which includes all Displayable objects as well as DisplayDevice . An object which wishes to allow the user to be able to change its colors goes through these steps:

  1. call ColorList::_color_category(char *) ; this adds a new category with the given name and returns a unique index for that category, or else returns the index of the category if it already exists. This index should be saved for later use.
  2. once a category exists, names should be added to the category that correspond to all the components that can be configured, with default colors. This is done by doing the following: (colors->color_category(catIndex))->add_name("item name", defaultColor)

  3. When the colors have been added, they may be retrieved later when creating a display list by doing the following: (colors->color_category(catIndex))->data("item name")

    This will return the index of the color assigned to the given item name.

ColorUser

 

Description

Simple base class for objects which will be needing to use a ColorList for colors. This class provides routines for being given a ColorList object, and for being informed of when colors are changed. The user can create new categories of colors in the ColorList, and add specific color objects to the category with an identifying name. The user can edit these colors via commands.

Constructors

Internal data structures

Virtual member functions

Method of use

ColorUser is a base class designed to be specified as a parent for some class which desires to use a ColorList to maintain categories of colors associated with names, and to make these names be customizeable to the user via the VMD user interfaces. All Displayable objects are derived from ColorUser , as are all DisplayDevice objects.

ColorList describes how to create new categories and how to access them. If a new class wishes to use these features, it should derive from ColorUser , and define versions of the protected virtual functions do_use_colors and do_color_changed. This first is designed to be only called once, right after the object is created -- it should create new categories, and add the necessary names to these categories. The second is designed to be called every time a particular color changes. The do_color_changed should check to see which color was modified, and then update itself if necessary.

DispCmd

 

Description

DispCmd is a base class for a large number of objects which are used to create the display lists in Displayable objects. Each subclass represents a particular drawing primitive, such as plotting a line, changing the current color, or applying a rotation. These objects take the data required for the particular primitive they represent (for example, the endpoints of a line, or the index of a color) and append this data to the end of the display list for a given Displayable . Routines are available to permit a DispCmd to be used more than once, and also to have the DispCmd remember the location where the data was most recently appended so that new data may be copied over existing data in a display list.

Constructors

Enumerations, lists or character name arrays

At the beginning of DispCmds.h is an enumeration with entries for all the different DispCmd -derived classes. These names are used by the render routine in each DisplayDevice to determine what the commands are in a display list. When new drawing primitives are added, a new name should be put in this list, and that name should be specified in the DispCmd base class constructor.

Following this are enumerations describing the different types of spheres that may be drawn, and the different types of lines.

Internal data structures

Nonvirtual member functions

Method of use

Each class derived from DispCmd should have two constructors:

If a derived class does not require any arguments (for example, the PUSH command, which just signals to push the top transformation matrix, but does not require any data itself), only the default constructor is used. Otherwise, each derived class should also provide two new functions;

Within the put and reput functions, DispCmd uses several routines in Displayable to start the action of writing a new command to the end of the display list, to copy over the data itself, and to signal the data is copied.

Suggestions for future changes/additions

At present, most Displayable objects contain instances of these commands as private members, which are used to create their internal display lists. This is not really necessary, it would probably be better if there were one global instance of each different DispCmd , available for use by the Displayable objects. This would decrease the memory used, and the time for construction of the Displayable using the global instances instead of a local copy.

DisplayDevice

 

Description

DisplayDevice is one of the main classes in VMD . It is a base class for all the objects which are responsible for drawing the current scene, either to an on-screen graphics window, or to a file. It is also responsible for encapsulating the window-manager-specific routines which are different for each type of windowing environment (e.g., GL-based window management and rendering, or X-Windows-based window management and OpenGL rendering, etc.). Finally, it is used to determine which item a pointer is currently selecting when a pointer button is pressed, either by a 2D mouse or by a 3D pointer. There are a large number of virtual functions which each subclass may define (if relevant). The DisplayDevice base class provides default versions for all the virtual functions, however, so that by default a bare DisplayDevice acts as an ``empty'' device, which essentially does nothing but which still functions to the rest of the program as a working DisplayDevice .

The main DisplayDevice instance used by VMD is also responsible for checking for and reporting window events, such as when the window is resized, or when a mouse button is pressed, etc. The main graphics window has one main popup menu (which could be implemented as a pulldown menu if required), which the DisplayDevice must be able to create and acquire events from.

There are two types of subclasses of DisplayDevice used in VMD :

Constructors

Enumerations, lists or character name arrays

Internal data structures

Virtual member functions

Method of use

Once a DisplayDevice has been defined, and an instance created, a simple sequence of routines are used to have the device render a scene. This sequence is implemented by the Scene::(DisplayDevice *display) routine. A Scene object maintains a list of display lists and Displayable objects which create those lists (see section 6.3.7). The draw routine uses the DisplayDevice as follows:

  1. display->prepare3D()
  2. Set the stereo mode to the left eye, or just normal, using the command display->left() or display->normal()
  3. For each Displayable in the Scene , the prepare routine is called to make that object ready to be drawn.
  4. For each display list maintained by the Scene , the command display->render(displist) is called.
  5. If the display is in stereo, display->right() is called and the previous step repeated.
  6. display->update()

Drawing to a file instead of the screen is almost identical, with the following exceptions:

Suggestions for future changes/additions

Currently, VMD uses the GL library (through a GLDisplayDevice ). To make VMD portable to a much larger number of platforms, a DisplayDevice using OpenGL and Xlib should be written, which will use the XFORMS library for the GUI.

Another suggestion is to change the current VMD style of constantly redrawing the screen to a style where the screen is only redrawn under any of these conditions:

Displayable

 

Description

The Displayable base class is the parent class for all items which need to be drawn to a DisplayDevice . For example, the set of axes which appear in the corner of the VMD display screen are maintained as a Displayable , and each Molecule is one as well. The Scene

(section 6.3.7) object maintains a list of all the Displayable 's that are to be drawn to the screen. Each Displayable consists of the following components:

The Displayable class is the fundamental building block for all items which want to draw something to the screen. Consequently, it is a rather complicated beast.

Constructors

Enumerations, lists or character name arrays

TransMethod is a public enumeration which is used to indicate the method of use of the objects transformation matrix. It is one of the following:

Internal data structures

Virtual member functions

Method of use

A Displayable must either be registered with a parent (i.e. be a child of some parent), or it must be registered with a Scene (in which case it cannot be the child of any other Displayable ). To create a new class derived from Displayable , you need to provide two constructors, one taking a Scene pointer, one a Displayable

pointer.

Once created, then in the derived-class-provided prepare routine, the display list of for the Displayable must be set up. If this display list will never change during the program, it can be done just once in the constructor and no prepare is necessary. The display list is created by using DispCmd objects.

The display list for each Displayble must be given to a Scene , regardless of whether it is child or parent or both. It is these display lists which are given to the DisplayDevice to be rendered. The Scene keeps a list of registered Displayable 's as well so that it can prepare them for drawing. When a parent is prepared for drawing, it also prepares all its children, so only top-level parents need to be registered with the Scene .

Since this class is derived from Pickable and ColorUser , there are several virtual functions which may need to be supplied in order for the derived Displayable to be picked by the pointers, or to have access to the color database. See the descriptions of these objects for more info.

One note about the display lists: the reason they are done in the current scheme is that the CAVE requires the use of shared memory to hold the information for the rendering processes to draw, while a separate update process keeps track of updating the information in shared memory. Since the shared memory cannot have pointers to non-shared memory locations, the display lists are designed to ONLY hold integer and floating-point data. When drawing in the CAVE, a special CaveScene supplies shared memory blocks for the Displayable 's to use for their display lists.

Suggestions for future changes/additions

Right now every item is redrawn each time through the VMD event loop. However, there are times when nothing changes, and no redraw is necessary. The prepare routine might be modified to have it return TRUE if a redraw is needed, so that if none of the current Displayable 's need a redraw, that extra work is avoided.

Also, this class is kind of a mess, but most of it is necessary ...

Matrix4

 

Description

A 4 by 4 matrix of floats, used primarily for the transformation matrix of Displayable and DisplayDevice objects. Along with general routines to rotate, translate, and scale the matrix, this also contains overloaded operators for = (copy, either a matrix or a scalar), *= (multiply, by either a matrix or a scalar), and += (add a matrix).

There are many functions in this class to simply add or multiply the matrix, to take the inverse of the matrix, or to apply rotations, translations, etc. Most importantly, functions exist to take a 3- or 4-vector, and multiply (transform) it by this matrix.

Constructors

Internal data structures

Method of use

The many functions in this class are not listed here. The most common use of this is to maintain a transformation matrix for transforming 3D vectors from one coordinate space to another, i.e. to rotate, translate, and scale them. Once a 4 by 4 matrix `M' has been set up, then a vector `V' is tranformed and placed in the view vector `VT' as: M.multpoint3d(V, VT)

Scene

 

Description

The Scene maintains and organizes a database with all the Displayable objects which are to be drawn by a DisplayDevice . It contains routines to add new Displayable 's to its database, and to draw them to the screen or to a file. It is derived from PickList , and so maintains the information about what diffent picking modes are available, as well routines to pick an item with a pointer.

There are two different sets of lists stored by the Scene , with each list kept for both the 2D case and the 3D case. The lists are:

This object also contains routines to apply a constant rotation to all Displayable 's each time they are drawn, as well as to apply general transformations to all the items in the scene. The most important function of Scene is, however, to draw the scene to a display or to a file.

Constructors

Internal data structures

Virtual member functions

Method of use

A Scene is created at the start of the program, and all Displayable

objects should be added to that scene (or to another Displayable as a child). It is used in the primary event loop to prepare and draw all the Displayable 's. It is also used to pick items with a pointer. The global routine VMDupdate contains an example of using a Scene object.

There are two derived classes from Scene :

Suggestions for future changes/additions

As mentioned for Displayable , the prepare routine could be modified to return a flag indicating whether anything has changed in the Displayable objects which would require a redraw. If nothing changed, then a redraw could be avoided.



next up previous contents
Next: Molecule objects Up: Function and Class Previous: Utility objects



Andrew Dalke
Wed May 15 02:25:03 CDT 1996