1 package org.catacomb.dataview.formats;
2
3 import java.io.File;
4
5 import org.catacomb.datalish.Box;
6 import org.catacomb.dataview.display.ViewConfig;
7 import org.catacomb.graph.gui.Geom;
8 import org.catacomb.graph.gui.Painter;
9 import org.catacomb.report.E;
10 import org.catacomb.util.ArrayUtil;
11
12
13 public class Mesh2plusTimeDisplay implements DataHandler {
14
15 double zval = 0.;
16
17 double zrange = 0.1;
18
19
20
21 String[] plotNames;
22
23 double[] frameValues;
24
25 double[][][] mesh;
26 double[][][] data;
27
28 boolean[] mask;
29
30 double[][][] innerMesh;
31
32 int varIdx;
33 int frameIdx;
34
35 private Box meshBox;
36
37 String plot;
38
39 String viewStyle = "density";
40
41 TableDataHandler coHandler = new TableDataHandler();
42
43
44 double zMask = -999.;
45
46 public void setZValue(double d) {
47 zval = d;
48 }
49
50
51 public String getMagic() {
52 return "cctdif2d";
53 }
54
55
56 public void read(File f) {
57 TableDataReader tdr = new TableDataReader(coHandler);
58 MeshDataReader mdr = new MeshDataReader(f, tdr);
59 mdr.read();
60 tdr.fix();
61
62 mesh = mdr.getMesh();
63
64 mask = new boolean[mesh.length];
65 for (int i = 0; i < mask.length; i++) {
66 mask[i] = true;
67 }
68
69
70 data = mdr.getData();
71 frameValues = mdr.getFrameValues();
72
73 String[] vn = mdr.getValueNames();
74 plotNames = new String[1 + vn.length];
75 plotNames[0] = "mesh";
76 for (int i = 0; i < vn.length; i++) {
77 plotNames[1 + i] = vn[i];
78 }
79 }
80
81
82
83 public void makeMeshMask() {
84 int nel = mesh.length;
85 double[] d = new double[nel];
86 double md = 1.e6;
87 double xcen = 0.;
88 for (int i = 0; i < nel; i++) {
89 double x = mesh[i][2][0] - zval;
90 d[i] = x;
91 if (Math.abs(x) < md) {
92 md = Math.abs(x);
93 xcen = x;
94 }
95 }
96
97 mask = new boolean[nel];
98 if (md > zrange) {
99
100 for (int i = 0; i < nel; i++) {
101 mask[i] = false;
102 }
103 } else {
104 for (int i = 0; i < nel; i++) {
105 if (Math.abs(d[i] - xcen) < 0.5 * zrange) {
106 mask[i] = true;
107 } else {
108 mask[i] = false;
109 }
110 }
111 }
112 zMask = zval;
113 }
114
115
116
117
118
119
120
121
122
123 public String[] getPlotNames() {
124 return plotNames;
125 }
126
127
128 public void setPlot(String s) {
129 varIdx = varidx(s);
130 }
131
132 private int varidx(String s) {
133 int dv = -1;
134 for (int i = 0; i < plotNames.length; i++) {
135 if (plotNames[i].equals(s)) {
136 dv = i - 1;
137 break;
138 }
139 }
140 return dv;
141 }
142
143
144
145 public double[] getFrameData(String s, int fidx) {
146 int vi = varidx(s);
147 double[] ret = data[fidx][vi];
148 return ret;
149 }
150
151
152 public void setDisplayVariable(int i) {
153 varIdx = i;
154 }
155
156
157 public double getMinValue() {
158 int vi = varIdx;
159 if (vi < 0) {
160 vi = 0;
161 }
162 return ArrayUtil.minD(data[frameIdx][vi]);
163
164 }
165
166
167 public double getMaxValue() {
168 int vi = varIdx;
169 if (vi < 0) {
170 vi = 0;
171 }
172
173 return ArrayUtil.maxD(data[frameIdx][vi]);
174 }
175
176
177 public boolean antialias() {
178
179 return false;
180 }
181
182
183 private void makeInnerMesh() {
184 innerMesh = new double[mesh.length][2][];
185 for (int i = 0; i < mesh.length; i++) {
186 double[][] di = Geom.innerPolygon(mesh[i][0], mesh[i][1]);
187 innerMesh[i][0] = di[0];
188 innerMesh[i][1] = di[1];
189 }
190 }
191
192
193 public void instruct(Painter p) {
194 if (varIdx < 0) {
195 instructMesh(p);
196 } else {
197 instructAreas(p);
198 }
199 }
200
201
202 public void instructMesh(Painter p) {
203
204 if (Math.abs(zMask - zval) > 0.1 * zrange) {
205 makeMeshMask();
206 }
207
208
209 int nel = mesh.length;
210 p.setColorWhite();
211
212 for (int i = 0; i < nel; i++) {
213 if (mask[i]) {
214 double[] xb = mesh[i][0];
215 double[] yb = mesh[i][1];
216
217 p.drawPolygon(xb, yb, xb.length);
218 }
219 }
220
221 if (innerMesh == null) {
222 makeInnerMesh();
223 }
224 p.setColorCyan();
225
226
227
228
229
230
231
232
233
234 }
235
236
237
238 public void instructAreas(Painter p) {
239
240 if (Math.abs(zMask - zval) > 0.01) {
241 makeMeshMask();
242 }
243
244
245 if (viewStyle.equals("density")) {
246 instructDensity(p);
247 } else {
248 E.info("missing code - drawing density");
249 instructDensity(p);
250 }
251 }
252
253
254 public void instructDensity(Painter p) {
255 if (frameIdx >= 0 && frameIdx < data.length && varIdx >= 0 && varIdx < data[frameIdx].length) {
256 double[] dat = data[frameIdx][varIdx];
257
258 p.drawColoredCells(mesh, dat, mask);
259
260
261 }
262 }
263
264
265
266
267 public Box getLimitBox() {
268 if (meshBox == null) {
269 if (mesh != null) {
270 meshBox = new Box();
271 for (int i = 0; i < mesh.length; i++) {
272 meshBox.push(mesh[i][0], mesh[i][1]);
273 }
274 }
275 }
276 return meshBox;
277 }
278
279
280 public double[] getFrameValues() {
281 return frameValues;
282 }
283
284 public int getContentStyle() {
285 return FRAMES2D;
286 }
287
288
289 public void setFrame(int ifr) {
290 frameIdx = ifr;
291 }
292
293
294 public String[] getViewOptions() {
295 String[] ret = {"density", "particles"};
296 return ret;
297 }
298
299
300 public void setViewStyle(String s) {
301 viewStyle = s;
302 }
303
304
305 public DataHandler getCoHandler() {
306 return coHandler;
307 }
308
309
310 public boolean hasData() {
311 return true;
312 }
313
314
315 public String getXAxisLabel() {
316
317 return null;
318 }
319
320
321 public String getYAxisLabel() {
322
323 return null;
324 }
325
326
327 public ViewConfig getViewConfig(String s) {
328
329 return null;
330 }
331
332 }