-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawContours.java
More file actions
433 lines (366 loc) · 13.3 KB
/
Copy pathDrawContours.java
File metadata and controls
433 lines (366 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
package quest;
import iisc.dsl.picasso.common.PicassoConstants;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.util.Arrays;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYAreaRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.ShapeUtilities;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
public class DrawContours
{
boolean logScale = true;
XYSeries cont[][];
XYSeries selPath;
XYSeries selPoint;
XYPlot plot;
XYAreaRenderer areaRend;
BouquetDriver bouquetDriverObj;
public DrawContours(AllObjects allObjects)
{
allObjects.setDrawContoursObj(this);
}
JPanel drawContour(AllObjects allObjects, int width, int height)
{
BouquetData bouquetDataObj = allObjects.getBouquetDataObj();
bouquetDriverObj = allObjects.getBouquetDriverObj();
int totalPlans = bouquetDataObj.getTotalPlans();
int totalContours = bouquetDataObj.getTotalContours();
int contourPlansCount[] = bouquetDataObj.getContourPlansCount();
int finalPlansSet[] = bouquetDataObj.getFinalPlanSet();
int dimension = bouquetDataObj.getDimension();
int resolution = bouquetDataObj.getResolution();
String errorProneRelationNames[] = bouquetDataObj.getErrorProneBaseRelationNames();
JPanel plotPanel = new JPanel();
cont = new XYSeries[totalContours+1][totalPlans];
int contourLocation[] = bouquetDataObj.getContourLocationInESS();
for(int i=0;i<=totalContours;i++)
{
for(int j=0;j<totalPlans;j++)
{
if(i==totalContours)
cont[i][j]=new XYSeries("P"+(j+1));
else
cont[i][j]=new XYSeries("Plan"+(i+1)+""+(j+1));
}
}
selPath = new XYSeries("Selectivity Path");
selPoint = new XYSeries("selectivity Point");
int spaceSize[]=new int [dimension];
for(int i=0;i<dimension;i++)
{
spaceSize[i]=resolution;
}
int totalPoints = (int)Math.pow(resolution, dimension);
for(int i=totalPoints-1;i>=0;i--)
{
if(contourLocation[i]!=0)
{
int spaceLocation[] = indexCalc(spaceSize, i, dimension);
int planIndex = bouquetDriverObj.getOptimalPlan(i, finalPlansSet);
int contour = contourLocation[i];
if(logScale)
cont[contour-1][planIndex].add(bouquetDriverObj.picsel[spaceLocation[0]], bouquetDriverObj.picsel[spaceLocation[1]]);
else
cont[contour-1][planIndex].add(spaceLocation[0], spaceLocation[1]);
}
}
double minLolations[][][] = new double[totalContours][totalPlans][dimension];
double maxLocations[][][] = new double[totalContours][totalPlans][dimension];
int contourPlans[][] = bouquetDataObj.getContourPlans();
for(int i=0;i<totalContours;i++)
{
for(int j=0;j<contourPlansCount[i];j++)
{
int plan = contourPlans[i][j];
int index = Arrays.binarySearch(finalPlansSet, plan);
double minX = cont[i][index].getMinX();
double minY = cont[i][index].getMinY();
double maxX = cont[i][index].getMaxX();
double maxY = cont[i][index].getMaxY();
minLolations[i][index][0] = minX;
minLolations[i][index][1] = maxY;
maxLocations[i][index][0] = maxX;
maxLocations[i][index][1] = minY;
}
}
bouquetDataObj.setPlanLocationMinCoordinate(minLolations);
bouquetDataObj.setPlanLocationMaxCoordinate(maxLocations);
XYSeriesCollection xySerCol= new XYSeriesCollection();
for(int i=0;i<=totalContours;i++)
{
for(int j=0;j<totalPlans;j++)
{
xySerCol.addSeries(cont[i][j]);
}
}
xySerCol.addSeries(selPath);
xySerCol.addSeries(selPoint);
XYDataset xyDataset = xySerCol;
JFreeChart chart = ChartFactory.createXYLineChart
("Isocost Contours in ESS (log-log scale)",errorProneRelationNames[0], errorProneRelationNames[1],
xyDataset, PlotOrientation.VERTICAL, true, true, false);
if(allObjects.demo_mode)
chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 12));
plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.WHITE);
LegendTitle legend = chart.getLegend();
Font labelFont;
if(allObjects.demo_mode)
labelFont = new Font("SansSerif", Font.BOLD, 12);
else
labelFont = new Font("SansSerif", Font.BOLD, QUESTConstants.AXIS_LABEL_FONT_SIZE); //For demo
legend.setItemFont(labelFont);
legend.setPosition(RectangleEdge.RIGHT);
// plot.setDomainGridlinePaint(Color.black);
// plot.setRangeGridlinePaint(Color.black);
// plot.getRenderer().setSeriesVisibleInLegend(0, false);
// plot.getRenderer().setSeriesPaint(totalContours, Color.BLACK);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
// renderer.setSeriesShapesVisible((totalContours+1)*BouquetDriver.planSet.length+1, true);
// renderer.setSeriesLinesVisible((totalContours+1)*BouquetDriver.planSet.length+1, false);
//
// renderer.setSeriesShapesVisible((totalContours+1)*BouquetDriver.planSet.length+2, true);
// renderer.setSeriesLinesVisible((totalContours+1)*BouquetDriver.planSet.length+2, false);
for(int i=0;i<=totalContours;i++)
{
for(int j=0;j<totalPlans;j++)
{
renderer.setSeriesStroke(i*totalPlans + j, new BasicStroke(1.5f));
// plot.getRenderer().setSeriesPaint(i*totalPlans + j, new Color(PicassoConstants.color[j]));
plot.getRenderer().setSeriesPaint(i*totalPlans + j, new Color(PicassoConstants.color[finalPlansSet[j] % PicassoConstants.color.length]));
if(i!=totalContours)
{
plot.getRenderer().setSeriesVisibleInLegend(i * totalPlans + j, false);
}
if(i == totalContours-1)
{
renderer.setSeriesShapesVisible(i*totalPlans + j, true);
Shape s = ShapeUtilities.createDiamond(2.0f);
renderer.setSeriesShape(i*totalPlans + j, s);
}
}
}
/*
* For simulated selectivity point.
*/
Shape s = new Ellipse2D.Double(0, 0, 5, 5);
renderer.setSeriesVisibleInLegend((totalContours+1)*totalPlans+1, false);
renderer.setSeriesShapesVisible((totalContours+1)*totalPlans+1, true);
renderer.setSeriesShape((totalContours+1)*totalPlans+1, s);
/*
* For selectivity Path
*/
plot.getRenderer().setSeriesPaint((totalContours+1)*totalPlans, Color.BLACK);
plot.getRenderer().setSeriesVisibleInLegend((totalContours+1)*totalPlans, false);
renderer.setSeriesShapesVisible((totalContours+1)*totalPlans, true);
renderer.setSeriesStroke(
(totalContours+1)*totalPlans, new BasicStroke(
1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {5.0f, 6.0f}, 0.0f
)
);
if(logScale)
{
LogAxis x = new LogAxis(errorProneRelationNames[0]+" selectivity");
LogAxis y = new LogAxis(errorProneRelationNames[1]+" selectivity");
x.setBase(2);
y.setBase(2);
x.setTickUnit(new NumberTickUnit(2));
y.setTickUnit(new NumberTickUnit(2));
plot.setDomainAxis(x);
plot.setRangeAxis(y);
if(allObjects.demo_mode)
{
x.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
x.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
y.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
y.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
x.setMinorTickMarksVisible(false);
y.setMinorTickMarksVisible(false);
x.setStandardTickUnits(NumberAxis.createStandardTickUnits());
y.setStandardTickUnits(NumberAxis.createStandardTickUnits());
y.setAutoRange(false);
x.setAutoRange(false);
}
else
{
x.setTickLabelFont(new Font("SansSerif", Font.PLAIN, QUESTConstants.AXIS_LABEL_FONT_SIZE)); //For demo
x.setLabelFont(new Font("SansSerif", Font.BOLD, QUESTConstants.AXIS_LABEL_FONT_SIZE));
y.setTickLabelFont(new Font("SansSerif", Font.PLAIN, QUESTConstants.AXIS_TICK_FONT_SIZE));
y.setLabelFont(new Font("SansSerif", Font.BOLD, QUESTConstants.AXIS_LABEL_FONT_SIZE));
}
// x.setNumberFormatOverride(currencyFormat);
// y.setNumberFormatOverride(currencyFormat);
// x.setStandardTickUnits(NumberAxis.createStandardTickUnits());
// y.setStandardTickUnits(NumberAxis.createStandardTickUnits());
//
// y.setAutoRange(false);
// x.setAutoRange(false);
x.setLowerBound(0.031);
y.setLowerBound(0.031);
// x.setRange(bouquetDriverObj.picsel[0]/2, 100);
// y.setRange(bouquetDriverObj.picsel[0]/2, 100);
}
else
{
NumberAxis domain = (NumberAxis)plot.getDomainAxis();
NumberAxis range = (NumberAxis)plot.getRangeAxis();
// range.setTickUnit(new NumberTickUnit(10));
domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, QUESTConstants.AXIS_TICK_FONT_SIZE));
domain.setLabelFont(new Font("SansSerif", Font.BOLD, QUESTConstants.AXIS_LABEL_FONT_SIZE));
range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, QUESTConstants.AXIS_TICK_FONT_SIZE));
range.setLabelFont(new Font("SansSerif", Font.BOLD, QUESTConstants.AXIS_LABEL_FONT_SIZE));
}
XYDataset areaSeriesDataset = buildAreaSeriesCollection(bouquetDataObj);
plot.setDataset(1, areaSeriesDataset);
areaRend = new XYAreaRenderer();
plot.setRenderer(1, areaRend);
/* this code applies auto-range on domain and range axis
* added on Aug 20, 2014 */
if(!allObjects.demo_mode)
{
plot.getRangeAxis().setAutoRange(true);
plot.getDomainAxis().setAutoRange(true);
plot.configureRangeAxes();
plot.configureDomainAxes();
}
for(int i=0;i<totalContours;i++)
{
for(int j=0;j<totalPlans;j++)
{
areaRend.setSeriesPaint(i*totalPlans + j, new Color(0,0,255,0));
// areaRend.setSeriesPaint(i*totalPlans + j, new Color(PicassoConstants.AreaColor[j], true));
areaRend.setSeriesVisibleInLegend(i*totalPlans + j, false);
}
}
ChartPanel cPanel = new ChartPanel(chart);
// cPanel.setPreferredSize(new Dimension(500, 400)); //uncomment
// cPanel.setPreferredSize(new Dimension(500, 380)); //For demo
// cPanel.setPreferredSize(new Dimension(350, 250));
cPanel.setPreferredSize(new Dimension(width, height));
plotPanel.add(cPanel);
plotPanel.setBackground(Color.WHITE);
return(plotPanel);
}
XYSeriesCollection buildAreaSeriesCollection(BouquetData bouquetDataObj)
{
float picsel[] = bouquetDriverObj.picsel;
XYSeriesCollection areaSeriesColl = new XYSeriesCollection();
int contour = bouquetDataObj.getTotalContours();
int totalPlans = bouquetDataObj.getTotalPlans();
for(int i=0;i<contour;i++)
{
for(int j=0;j<totalPlans;j++)
{
if(cont[i][j].getItemCount()!=0)
{
double minX= cont[i][j].getMinX();
if(minX>0.005)
// if(minX>0)
{
XYSeries s = new XYSeries("Plan"+(i+1)+","+(j+1));
if(logScale)
s.add(picsel[0], cont[i][j].getMaxY());
else
s.add(0, cont[i][j].getMaxY());
for(int k=0;k<cont[i][j].getItemCount();k++)
{
XYDataItem datapoint= cont[i][j].getDataItem(k);
s.add(datapoint);
}
areaSeriesColl.addSeries(s);
}
else
{
areaSeriesColl.addSeries(cont[i][j]);
}
}
else
{
areaSeriesColl.addSeries(cont[i][j]);
}
}
}
return(areaSeriesColl);
}
//Column major
int[] indexCalc(int size[], int address, int dim)
{
int maxAdd=1;
for(int i=0;i<dim;i++)
{
maxAdd *= size[i];
}
if(address >= maxAdd)
{
System.err.println("Error: Address in invalid");
System.exit(0);
}
int index[] = new int [dim];
for(int i=0;i<dim;i++)
{
int n;
n = address % size[i];
address = address / size[i];
index[i] = n;
}
return(index);
}
void changeContourColor(int contour,int plan, int totalPlans, int finalPlanSet[])
{
// plot.getRenderer().setSeriesPaint(contour * totalPlans + plan, Color.BLACK);
// areaRend.setSeriesPaint(contour * totalPlans + plan, new Color(PicassoConstants.AreaColor[plan], true));
plot.getRenderer().setSeriesPaint(contour * totalPlans + plan, Color.BLACK);
areaRend.setSeriesPaint(contour * totalPlans + plan, new Color(PicassoConstants.AreaColor[finalPlanSet[plan] % PicassoConstants.AreaColor.length], true));
}
void path(int x,int y,int steps)
{
if(logScale)
selPath.add(bouquetDriverObj.picsel[x], bouquetDriverObj.picsel[y]);
else
selPath.add(x, y);
}
void resetContoursPlot(AllObjects allObjects)
{
BouquetData bouquetDataObj = allObjects.getBouquetDataObj();
int totalContours = bouquetDataObj.getTotalContours();
int totalPlans = bouquetDataObj.getTotalPlans();
int finalPlanSet[] = bouquetDataObj.finalPlanSet;
for(int i=0;i<=totalContours;i++)
{
for(int j=0;j<totalPlans;j++)
{
plot.getRenderer().setSeriesPaint(i*totalPlans + j, new Color(PicassoConstants.color[finalPlanSet[j] % PicassoConstants.color.length]));
areaRend.setSeriesPaint(i*totalPlans + j, new Color(0,0,255,0));
}
}
selPath.clear();
}
void addSelectivityPoint(double sel[])
{
selPoint.clear();
selPoint.add(sel[0], sel[1]);
}
void clearSelectivityPoint()
{
selPoint.clear();
}
}