View Javadoc

1   package org.catacomb.numeric.mesh;
2   
3   import org.catacomb.interlish.structure.Mesh;
4   import org.catacomb.interlish.structure.MeshBuilder;
5   
6   import java.util.HashMap;
7   
8   
9   
10  public class DifMeshBuilder implements MeshBuilder {
11  
12  
13      DifMesh dmesh;
14  
15      int npoint;
16      MeshPoint[] points;
17  
18      HashMap<Object, DifMeshPoint> peerHM;
19  
20  
21  
22  
23      public void startMesh() {
24          peerHM = new HashMap<Object, DifMeshPoint>();
25          points = new DifMeshPoint[100];
26          npoint = 0;
27      }
28  
29  
30  
31      public Object newPoint(double x, double y, double z, double r, int idx,
32                             Object peer) {
33          DifMeshPoint dmp = new DifMeshPoint(x, y, z, r, idx);
34  
35          peerHM.put(peer, dmp);
36  
37          addPoint(dmp);
38  
39          return dmp;
40      }
41  
42  
43  
44      public void addPoint(DifMeshPoint pt) {
45  
46          if (npoint >= points.length) {
47              MeshPoint[] dmpa = new MeshPoint[(3 * npoint) / 2];
48              for (int i  = 0; i < npoint; i++) {
49                  dmpa[i] = points[i];
50              }
51              points = dmpa;
52          }
53  
54          points[npoint++] = pt;
55      }
56  
57  
58  
59      private DifMeshPoint getPoint(Object obj) {
60          return peerHM.get(obj);
61      }
62  
63  
64  
65  
66      public void connectToPeer(Object mp1, Object o2) {
67          DifMeshPoint dmpa = (DifMeshPoint)mp1;
68          DifMeshPoint dmpb = getPoint(o2);
69  
70          dmpa.addNeighbor(dmpb);
71          dmpb.addNeighbor(dmpa);
72      }
73  
74  
75  
76  
77  
78      public Mesh getMesh() {
79          DifMesh dm= new DifMesh();
80  
81          trimPointArray();
82  
83          dm.setPoints(points);
84  
85          return dm;
86      }
87  
88  
89  
90  
91      public void trimPointArray() {
92          if (points.length != npoint) {
93  
94              MeshPoint[] dmpa = new MeshPoint[npoint];
95              for (int i = 0; i < npoint; i++) {
96                  dmpa[i] = points[i];
97              }
98  
99              points = dmpa;
100         }
101     }
102 
103 }