next up previous contents index
Next: Draw and Drawing Extensions Up: User-Defined Graphics Previous: Animation   Contents   Index


Graphics

This section describes technical aspects of how the graphics commands are implemented and used. It should be read by those who want to understand how to build script-level extensions and those who like knowing more about how things work.

The user controlled graphics are implemented as if they are molecules of zero length which contains only a list of graphical objects. (Indeed, internally the class is called ``MoleculeGraphics'' and is derived from the Molecule class.) Thus, all the normal controls are applicable, and this is why the graphics ``molecules'' are on the Mol form. This simplifies matters as many of the controls, such as the mouse controls, do not need to be duplicated. However, some of the commands that apply only to molecules then make no sense, such as the graphics form.

Multiple graphics lists can be created. Since they are just specializations of a normal molecule, they are created with the mol load command, just like any other molecule. The full command is:

The name parameter should be a distictive string related to the molecule. For instance, if the purpose of a new graphics list is to read in a graphics file format, the name should be the file name. If it is a method of viewing data from another, loaded molecule, the name should contain the name of the method and the molecule Id of the molecule from which it was derived. VMD reserves the name ``graphics'' for use with the draw command as that command always adds its graphics to the last graphical molecule with that name.

Once the graphics list is loaded and on the list of molecules, it can be distinguished from a normal molecule by using the molinfo <molID> get source command, which returns ``Graphics'' for graphics molecules.

The information pertaining to a given graphics list is accessed via the graphics command, which is of the following form:

where the "molecule id" is the id of the graphics molecule on the molecule list. The command field can be one of the graphical items listed in section §, or one of the commands exists, delete, replace, list or info. The graphics command returns a value, which depends on the command given.

As graphical primitives are added to the list they are assigned a unique, increasing value. The first object added is assigned $0$, the second is assigned $1$, etc. The commands which add an item return its value. A list of the available object ids is available with the list command. To test if a specific primitive exists, use the exists command followed by the object index. This returns a $1$ if the index exists, and $0$ if it does not. Information can be retrieved about a given item with the info command. This takes one option, which is the number of graphical information from which information is desired.

A given primitive is deleted with the delete command followed by the index of the object to delete. It does not have a return value. If the parameter is the string all, then all the primitives are deleted and the index count reset to 0.

Another deletion method allows one primitive to be replaced by another; suspiciously enough, this is the replace command. What it does is delete the given primitive and set things up so the next primitive is put in the same spot on the list and given the same index. This is designed for situations where the graphics are complicated to build, but where the colors might want to be easily changed. The color definition can be replaced without needing to rebuild the full list.

Here are examples of all the above commands:

vmd > mol load graphics testing
Info) Loading new molecule ...
vmd > graphics top sphere {0.1 0.2 0.3} radius 0.4
Info) 0
vmd > graphics top cylinder {-1 -1 -1} {2.6 2.5 2.4} resolution 3
Info) 1
vmd > graphics top line {0 0 0} {3 0 0} style dashed
Info) 2
vmd > graphics top delete 1
vmd > graphics top list
Info) 0 2
vmd > graphics top exists 0
Info) 1
vmd > graphics top exists 1
Info) 0
vmd > graphics top info 0
Info) sphere {0.100000 0.200000 0.300000} radius 0.400000 resolution 6
vmd > graphics top replace 0
vmd > graphics top point {3.3 2.2 1.1}
Info) 0
vmd > graphics top info 0
Info) point {3.300000 2.200000 1.100000}
vmd > graphics top list
Info) 0 2


next up previous contents index
Next: Draw and Drawing Extensions Up: User-Defined Graphics Previous: Animation   Contents   Index
vmd@ks.uiuc.edu