1 package com.github.celldynamics.quimp.plugin.qanalysis;
2
3 import java.io.File;
4
5
6
7
8
9 import org.scijava.vecmath.Color3f;
10 import org.scijava.vecmath.Point3f;
11
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
21
22 public class STMap3D {
23
24
25
26
27 double[][] xMap;
28
29
30
31 double[][] yMap;
32
33
34
35
36 int[] colors;
37
38
39
40
41 int VERTS;
42
43
44
45
46 int RES;
47
48
49
50
51 int TIME;
52
53
54
55
56 VRMLobject cell3d;
57
58
59
60
61
62
63
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
77
78 void build() {
79 Point3f[] coords = new Point3f[VERTS];
80 Color3f[] colorsF = new Color3f[VERTS];
81 int coCount = 0;
82
83
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
90
91
92
93
94
95 coCount++;
96 }
97
98 }
99
100
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
118 }
119
120
121
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
133
134
135
136 void toOrigin(ExtendedVector2d centre) {
137 cell3d.transform((float) -centre.getX(), 0, (float) -centre.getY());
138 }
139
140
141
142
143
144
145 void scale(float f) {
146 cell3d.scale(f);
147 }
148
149
150
151
152
153
154 void write(File CELL) {
155 if (CELL.exists()) {
156 CELL.delete();
157 }
158 cell3d.write(CELL);
159 }
160 }