Back to index

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

The representation of a Chemical .xyz or Atomic Lattice (.lat) model. More...

Collaboration diagram for XYZLatModel:
Collaboration graph
[legend]

List of all members.

Package Functions

 XYZLatModel ()
 XYZLatModel (InputStream is, boolean labl, boolean bx, boolean bnds, Color bgcolor, Color bndcolor, Color bxcolor) throws Exception
 Create a Chemical 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.

Package Attributes

float vert []
ScaleableAtom atoms []
int tvert []
int ZsortMap []
int nvert
int maxvert
int bond [][] = new int[300][2]
int nbond = -1
boolean box
boolean label
boolean bonds
int br
int bg
int bb
int gr
int gg
int gb
int xr
int xg
int xb
boolean transformed
Matrix3D mat
float xmin
float xmax
float ymin
float ymax
float zmin
float zmax

Static Package Attributes

static Hashtable atomTable
static ScaleableAtom defaultAtom

Detailed Description

The representation of a Chemical .xyz or Atomic Lattice (.lat) model.

Definition at line 116 of file LatticeViewer.java.


Constructor & Destructor Documentation

XYZLatModel.XYZLatModel ( ) [inline, package]

Definition at line 140 of file LatticeViewer.java.

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

Here is the call graph for this function:

XYZLatModel.XYZLatModel ( InputStream  is,
boolean  labl,
boolean  bx,
boolean  bnds,
Color  bgcolor,
Color  bndcolor,
Color  bxcolor 
) throws Exception [inline, package]

Create a Chemical model by parsing an input stream.

Definition at line 148 of file LatticeViewer.java.

    {
       this();
       StreamTokenizer st;
       st = new StreamTokenizer(new BufferedInputStream(is, 4000));
       st.eolIsSignificant(true);
       st.commentChar('#');
       int slot = 0;
      
       this.label=labl;
       this.box=bx;
       this.bonds=bnds;
       this.br=bndcolor.getRed();
       this.bg=bndcolor.getGreen();
       this.bb=bndcolor.getBlue();
       this.gr=bgcolor.getRed();
       this.gg=bgcolor.getGreen();
       this.gb=bgcolor.getBlue();
       this.xr=bxcolor.getRed();
       this.xg=bxcolor.getGreen();
       this.xb=bxcolor.getBlue();
       atomTable = new Hashtable();
       defaultAtom = new ScaleableAtom(255, 100, 200, 1.0);
       try
       {
scan:
          while (true)
          {
             switch ( st.nextToken() ) 
             {
                case StreamTokenizer.TT_EOF:
                   break scan;
                default:
                   break;
                case StreamTokenizer.TT_WORD:
                   // get atom type
                   String name = st.sval;
                   if (name.equals("ATOM")) {
                       // get name, RGB colour and size
                       int r=255, g=255, b=255;
                       double s=1.0;
                       if (st.nextToken() == StreamTokenizer.TT_WORD) 
                       {
                           name=st.sval;
                           if (st.nextToken() == StreamTokenizer.TT_NUMBER) 
                           {
                              r = (int)st.nval;
                              if (st.nextToken() == StreamTokenizer.TT_NUMBER) 
                              {
                                 g = (int)st.nval;
                                 if (st.nextToken() == StreamTokenizer.TT_NUMBER)
                                 {
                                     b =(int)st.nval;
                                     if (st.nextToken() == StreamTokenizer.TT_NUMBER)
                                         s = (double)st.nval;
                                 }
                              }
                           }
                       }
                       if (s>=2.0) s=2.0;
                       if (s<0.0) s=1.0;
                      atomTable.put(name.toLowerCase(), new ScaleableAtom(r, g, b, s));
                   } else {
                       // get position
                       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);
                       // get connectivities
                       while (st.nextToken() == StreamTokenizer.TT_NUMBER)
                       {
                         nbond++;
                         bond[nbond][0]=nvert;
                         bond[nbond][1]=(int)st.nval;
                       }
                   }
                   while( st.ttype != StreamTokenizer.TT_EOL &&
                          st.ttype != StreamTokenizer.TT_EOF )
                   st.nextToken();

             }   // end Switch

          }  // end while

          is.close();

       }  // end Try
       catch( IOException e) {}

       if (st.ttype != StreamTokenizer.TT_EOF)
          throw new Exception(st.toString());

    }  // end XYZLatModel()

Here is the call graph for this function:


Member Function Documentation

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

Add a vertex to this model.

Definition at line 252 of file LatticeViewer.java.

                                                        {
       int i = nvert;
       if (i >= maxvert)
           if (vert == null) {
              maxvert = 100;
              vert = new float[maxvert * 3];
              atoms = new ScaleableAtom[maxvert];
           } else {
              maxvert *= 2;
              float nv[] = new float[maxvert * 3];
              System.arraycopy(vert, 0, nv, 0, vert.length);
              vert = nv;
              ScaleableAtom na[] = new ScaleableAtom[maxvert];
              System.arraycopy(atoms, 0, na, 0, atoms.length);
              atoms = na;
           }
       ScaleableAtom a = (ScaleableAtom) 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 XYZLatModel.findBB ( ) [inline, package]

Find the bounding box of this model.

Definition at line 384 of file LatticeViewer.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 XYZLatModel.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 293 of file LatticeViewer.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;
       ScaleableAtom ls[] = atoms;
        int drawn[] = new int[nbond+1];
       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;

            // draw bonds
            int v1, v2;
            boolean e = atoms[j/3].Exist();
            v1=j/3+1;
            if (((e)&&(bonds))||((!e)&&(box)))
            {
                for (int k=0; k<=nbond; k++)
                {
                    v2=-1;
                    if (bond[k][0]==v1)
                        v2=bond[k][1]-1;
                    if (bond[k][1]==v1)
                        v2=bond[k][0]-1;
                    if ((v2!=-1)&&(drawn[k]==0))
                    {
                        drawn[k]=1;
                        double rr=(v[j+2]+v[v2*3+2]+6)/36.0;
                        int r1,b1,g1;
                        if (e) {
                            r1=(int)(rr*(br-gr)+gr);
                            b1=(int)(rr*(bb-gb)+gb);
                            g1=(int)(rr*(bg-gg)+gg);
                        } else {
                            r1=(int)(rr*(xr-gr)+gr);
                            b1=(int)(rr*(xb-gb)+gb);
                            g1=(int)(rr*(xg-gg)+gg);
                        }   
                        Color line = new Color(r1,g1,b1);
                        g.setColor(line);
                        g.drawLine(v[j],v[j+1],v[v2*3],v[v2*3+1]);
                    }
                }
            }
            if (e)
               atoms[j/3].paint(g, v[j], v[j + 1], grey);
            if (label) {
                g.setColor(Color.black);
               g.drawString(String.valueOf(v1), v[j], v[j+1]); 
            }
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XYZLatModel.transform ( ) [inline, package]

Transform all the points in this model.

Definition at line 279 of file LatticeViewer.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

Definition at line 118 of file LatticeViewer.java.

Hashtable XYZLatModel.atomTable [static, package]

Definition at line 131 of file LatticeViewer.java.

int XYZLatModel.bb [package]

Definition at line 127 of file LatticeViewer.java.

int XYZLatModel.bg [package]

Definition at line 127 of file LatticeViewer.java.

int XYZLatModel.bond[][] = new int[300][2] [package]

Definition at line 122 of file LatticeViewer.java.

Definition at line 126 of file LatticeViewer.java.

Definition at line 124 of file LatticeViewer.java.

int XYZLatModel.br [package]

Definition at line 127 of file LatticeViewer.java.

Definition at line 132 of file LatticeViewer.java.

int XYZLatModel.gb [package]

Definition at line 128 of file LatticeViewer.java.

int XYZLatModel.gg [package]

Definition at line 128 of file LatticeViewer.java.

int XYZLatModel.gr [package]

Definition at line 128 of file LatticeViewer.java.

Definition at line 125 of file LatticeViewer.java.

Definition at line 135 of file LatticeViewer.java.

int XYZLatModel.maxvert [package]

Definition at line 121 of file LatticeViewer.java.

int XYZLatModel.nbond = -1 [package]

Definition at line 123 of file LatticeViewer.java.

int XYZLatModel.nvert [package]

Definition at line 121 of file LatticeViewer.java.

Definition at line 134 of file LatticeViewer.java.

int XYZLatModel.tvert[] [package]

Definition at line 119 of file LatticeViewer.java.

float XYZLatModel.vert[] [package]

Definition at line 117 of file LatticeViewer.java.

int XYZLatModel.xb [package]

Definition at line 129 of file LatticeViewer.java.

int XYZLatModel.xg [package]

Definition at line 129 of file LatticeViewer.java.

float XYZLatModel.xmax [package]

Definition at line 137 of file LatticeViewer.java.

float XYZLatModel.xmin [package]

Definition at line 137 of file LatticeViewer.java.

int XYZLatModel.xr [package]

Definition at line 129 of file LatticeViewer.java.

float XYZLatModel.ymax [package]

Definition at line 137 of file LatticeViewer.java.

float XYZLatModel.ymin [package]

Definition at line 137 of file LatticeViewer.java.

float XYZLatModel.zmax [package]

Definition at line 137 of file LatticeViewer.java.

float XYZLatModel.zmin [package]

Definition at line 137 of file LatticeViewer.java.

int XYZLatModel.ZsortMap[] [package]

Definition at line 120 of file LatticeViewer.java.


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