Back to index

wims  3.65+svn20090927
Package Functions | Static Package Functions | Package Attributes | Static Package Attributes
XYZChemModel Class Reference

The representation of a Chemical .xyz model. More...

Collaboration diagram for XYZChemModel:
Collaboration graph
[legend]

List of all members.

Package Functions

 XYZChemModel ()
 XYZChemModel (InputStream is) throws Exception
 Create a Cehmical model by parsing an input stream.
int addVert (String name, float x, float y, float z)
 Add a vertex to this model.
void transform ()
 Transform all the points in this model.
void paint (Graphics g)
 Paint this model to a graphics context.
void findBB ()
 Find the bounding box of this model.

Static Package Functions

 [static initializer]

Package Attributes

float vert []
Atom atoms []
int tvert []
int ZsortMap []
int nvert
int maxvert
boolean transformed
Matrix3D mat
float xmin
float xmax
float ymin
float ymax
float zmin
float zmax

Static Package Attributes

static Hashtable atomTable = new Hashtable()
static Atom defaultAtom

Detailed Description

The representation of a Chemical .xyz model.

Definition at line 47 of file XYZApp.java.


Constructor & Destructor Documentation

XYZChemModel.XYZChemModel ( ) [inline, package]

Definition at line 74 of file XYZApp.java.

                    {
       mat = new Matrix3D();
       mat.xrot(20);
       mat.yrot(30);
    }

Here is the call graph for this function:

XYZChemModel.XYZChemModel ( InputStream  is) throws Exception [inline, package]

Create a Cehmical model by parsing an input stream.

Definition at line 82 of file XYZApp.java.

                                                   {
       this();
       StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(is, 4000));
       st.eolIsSignificant(true);
       st.commentChar('#');
       int slot = 0;
scan:
       while (true)
           switch (st.nextToken()) {
             case StreamTokenizer.TT_EOF:
              break scan;
             default:
              break;
             case StreamTokenizer.TT_WORD:
              String name = st.sval;
              double x = 0, y = 0, z = 0;
              if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                  x = st.nval;
                  if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                     y = st.nval;
                     if (st.nextToken() == StreamTokenizer.TT_NUMBER)
                         z = st.nval;
                  }
              }
              addVert(name, (float) x, (float) y, (float) z);
              while (st.ttype != StreamTokenizer.TT_EOL &&
                     st.ttype != StreamTokenizer.TT_EOF)
                  st.nextToken();
           }
       is.close();
       if (st.ttype != StreamTokenizer.TT_EOF)
           throw new Exception(st.toString());
    }

Here is the call graph for this function:


Member Function Documentation

XYZChemModel.[static initializer] ( ) [inline, static, package]
int XYZChemModel.addVert ( String  name,
float  x,
float  y,
float  z 
) [inline, package]

Add a vertex to this model.

Definition at line 117 of file XYZApp.java.

                                                        {
       int i = nvert;
       if (i >= maxvert)
           if (vert == null) {
              maxvert = 100;
              vert = new float[maxvert * 3];
              atoms = new Atom[maxvert];
           } else {
              maxvert *= 2;
              float nv[] = new float[maxvert * 3];
              System.arraycopy(vert, 0, nv, 0, vert.length);
              vert = nv;
              Atom na[] = new Atom[maxvert];
              System.arraycopy(atoms, 0, na, 0, atoms.length);
              atoms = na;
           }
       Atom a = (Atom) atomTable.get(name.toLowerCase());
       if (a == null) a = defaultAtom;
       atoms[i] = a;
       i *= 3;
       vert[i] = x;
       vert[i + 1] = y;
       vert[i + 2] = z;
       return nvert++;
    }

Here is the caller graph for this function:

void XYZChemModel.findBB ( ) [inline, package]

Find the bounding box of this model.

Definition at line 212 of file XYZApp.java.

                  {
       if (nvert <= 0)
           return;
       float v[] = vert;
       float xmin = v[0], xmax = xmin;
       float ymin = v[1], ymax = ymin;
       float zmin = v[2], zmax = zmin;
       for (int i = nvert * 3; (i -= 3) > 0;) {
           float x = v[i];
           if (x < xmin)
              xmin = x;
           if (x > xmax)
              xmax = x;
           float y = v[i + 1];
           if (y < ymin)
              ymin = y;
           if (y > ymax)
              ymax = y;
           float z = v[i + 2];
           if (z < zmin)
              zmin = z;
           if (z > zmax)
              zmax = z;
       }
       this.xmax = xmax;
       this.xmin = xmin;
       this.ymax = ymax;
       this.ymin = ymin;
       this.zmax = zmax;
       this.zmin = zmin;
    }

Here is the caller graph for this function:

void XYZChemModel.paint ( Graphics  g) [inline, package]

Paint this model to a graphics context.

It uses the matrix associated with this model to map from model space to screen space. The next version of the browser should have double buffering, which will make this much nicer

Definition at line 158 of file XYZApp.java.

                           {
       if (vert == null || nvert <= 0)
           return;
       transform();
       int v[] = tvert;
       int zs[] = ZsortMap;
       if (zs == null) {
           ZsortMap = zs = new int[nvert];
           for (int i = nvert; --i >= 0;)
              zs[i] = i * 3;
       }

       /*
        * I use a bubble sort since from one iteration to the next, the sort
        * order is pretty stable, so I just use what I had last time as a
        * "guess" of the sorted order.  With luck, this reduces O(N log N)
        * to O(N)
        */

       for (int i = nvert - 1; --i >= 0;) {
           boolean flipped = false;
           for (int j = 0; j <= i; j++) {
              int a = zs[j];
              int b = zs[j + 1];
              if (v[a + 2] > v[b + 2]) {
                  zs[j + 1] = a;
                  zs[j] = b;
                  flipped = true;
              }
           }
           if (!flipped)
              break;
       }

       int lg = 0;
       int lim = nvert;
       Atom ls[] = atoms;
       if (lim <= 0 || nvert <= 0)
           return;
       for (int i = 0; i < lim; i++) {
           int j = zs[i];
           int grey = v[j + 2];
           if (grey < 0)
              grey = 0;
           if (grey > 15)
              grey = 15;
           // g.drawString(names[i], v[j], v[j+1]);
           atoms[j/3].paint(g, v[j], v[j + 1], grey);
           // g.drawImage(iBall, v[j] - (iBall.width >> 1), v[j + 1] -
           // (iBall.height >> 1));
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XYZChemModel.transform ( ) [inline, package]

Transform all the points in this model.

Definition at line 144 of file XYZApp.java.

                     {
       if (transformed || nvert <= 0)
           return;
       if (tvert == null || tvert.length < nvert * 3)
           tvert = new int[nvert * 3];
       mat.transform(vert, tvert, nvert);
       transformed = true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Atom XYZChemModel.atoms[] [package]

Definition at line 49 of file XYZApp.java.

Hashtable XYZChemModel.atomTable = new Hashtable() [static, package]

Definition at line 54 of file XYZApp.java.

Atom XYZChemModel.defaultAtom [static, package]

Definition at line 55 of file XYZApp.java.

Definition at line 69 of file XYZApp.java.

int XYZChemModel.maxvert [package]

Definition at line 52 of file XYZApp.java.

int XYZChemModel.nvert [package]

Definition at line 52 of file XYZApp.java.

Definition at line 68 of file XYZApp.java.

int XYZChemModel.tvert[] [package]

Definition at line 50 of file XYZApp.java.

float XYZChemModel.vert[] [package]

Definition at line 48 of file XYZApp.java.

float XYZChemModel.xmax [package]

Definition at line 71 of file XYZApp.java.

float XYZChemModel.xmin [package]

Definition at line 71 of file XYZApp.java.

float XYZChemModel.ymax [package]

Definition at line 71 of file XYZApp.java.

float XYZChemModel.ymin [package]

Definition at line 71 of file XYZApp.java.

float XYZChemModel.zmax [package]

Definition at line 71 of file XYZApp.java.

float XYZChemModel.zmin [package]

Definition at line 71 of file XYZApp.java.

int XYZChemModel.ZsortMap[] [package]

Definition at line 51 of file XYZApp.java.


The documentation for this class was generated from the following file: