View Javadoc
1   package com.github.celldynamics.quimp.plugin.qanalysis;
2   
3   import java.io.File;
4   
5   // import javax.media.j3d.BranchGroup;
6   // import javax.media.j3d.IndexedQuadArray;
7   // import javax.media.j3d.QuadArray;
8   // import javax.media.j3d.Shape3D;
9   import org.scijava.vecmath.Color3f;
10  import org.scijava.vecmath.Point3f;
11  // import org.cybergarage.x3d.j3d.VRML97Saver;
12  
13  import com.github.celldynamics.quimp.QColor;
14  import com.github.celldynamics.quimp.geom.ExtendedVector2d;
15  import com.github.celldynamics.quimp.utils.QuimPArrayUtils;
16  import com.github.celldynamics.quimp.utils.graphics.vrml.VRMLobject;
17  
18  /**
19   *
20   * @author rtyson
21   */
22  public class STMap3D {
23  
24    /**
25     * The x map.
26     */
27    double[][] xMap;
28    /**
29     * The y map.
30     */
31    double[][] yMap;
32  
33    /**
34     * The colors.
35     */
36    int[] colors;
37  
38    /**
39     * The verts.
40     */
41    int VERTS;
42  
43    /**
44     * The res.
45     */
46    int RES;
47  
48    /**
49     * The time.
50     */
51    int TIME;
52  
53    /**
54     * The cell 3 d.
55     */
56    VRMLobject cell3d;
57  
58    /**
59     * Instantiates a new ST map 3 D.
60     *
61     * @param xm the xm
62     * @param ym the ym
63     * @param col the col
64     */
65    public STMap3D(double[][] xm, double[][] ym, int[] col) {
66      xMap = xm;
67      yMap = ym;
68      colors = col;
69  
70      RES = xm[0].length;
71      TIME = xm.length;
72      VERTS = col.length;
73    }
74  
75    /**
76     * Builds the.
77     */
78    void build() {
79      Point3f[] coords = new Point3f[VERTS];
80      Color3f[] colorsF = new Color3f[VERTS];
81      int coCount = 0;
82  
83      // int[] colIndices = new int[VERTS];
84  
85      for (int i = 0; i < xMap.length; i++) {
86        for (int j = xMap[0].length - 1; j >= 0; j--) {
87          coords[coCount] = new Point3f((float) xMap[i][j], (i * 1.0f), (float) yMap[i][j]);
88          colorsF[coCount] = QColor.colorInt23f(colors[(i * RES) + j]);
89          // if(i<30){
90          // colorsF[coCount] = new Color3f(0.5168f,0.0f,0.0f);
91          // }else{
92          // colorsF[coCount] = new Color3f(0.0f,0.0f,0.5532f);
93          // }
94          // colIndices[coCount] = coCount;
95          coCount++;
96        }
97  
98      }
99  
100     // int[] indices= new int[(RES*4)* (oH.getSize()-1)];
101     int[] indices = new int[(RES * 4) * (TIME - 1)];
102     System.out.println("indeices length: " + indices.length);
103 
104     int base;
105     for (int i = 0; i < indices.length; i += 4) {
106 
107       base = i / 4;
108 
109       indices[i] = base;
110       indices[i + 1] = base + 1;
111       indices[i + 2] = base + 1 + RES;
112       indices[i + 3] = base + RES;
113 
114       if (((i - ((RES - 1) * 4))) % (4 * RES) == 0) {
115         indices[i + 1] = base + 1 - RES;
116         indices[i + 2] = base + 1;
117         // System.out.print("\twraped: ");
118       }
119 
120       // System.out.println(""+indices[i] +"," +indices[i+1]+","
121       // +indices[i+2]+"," +indices[i+3]);
122     }
123 
124     System.out.println("coord length" + coords.length);
125     System.out.println("max index = " + QuimPArrayUtils.arrayMax(indices));
126 
127     cell3d = new VRMLobject(coords, colorsF, indices);
128 
129   }
130 
131   /**
132    * To origin.
133    *
134    * @param centre the centre
135    */
136   void toOrigin(ExtendedVector2d centre) {
137     cell3d.transform((float) -centre.getX(), 0, (float) -centre.getY());
138   }
139 
140   /**
141    * Scale.
142    *
143    * @param f the f
144    */
145   void scale(float f) {
146     cell3d.scale(f);
147   }
148 
149   /**
150    * Write.
151    *
152    * @param CELL the cell
153    */
154   void write(File CELL) {
155     if (CELL.exists()) {
156       CELL.delete();
157     }
158     cell3d.write(CELL);
159   }
160 }