| 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 |
package dr.geo; |
| 27 |
|
| 28 |
import javax.swing.*; |
| 29 |
import java.awt.*; |
| 30 |
import java.awt.geom.AffineTransform; |
| 31 |
import java.awt.geom.GeneralPath; |
| 32 |
import java.awt.geom.Point2D; |
| 33 |
import java.awt.geom.Rectangle2D; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class VisualizeKMLJointProb extends VisualizeKMLNumericalProbs { |
| 39 |
|
| 40 |
Point2D B; |
| 41 |
|
| 42 |
public VisualizeKMLJointProb(String kmlFileName) { |
| 43 |
|
| 44 |
super(kmlFileName); |
| 45 |
|
| 46 |
B = athens; |
| 47 |
|
| 48 |
if (rejector.reject(0.0, new double[]{B.getX(), B.getY()})) { |
| 49 |
throw new RuntimeException("The B position was rejected!"); |
| 50 |
} |
| 51 |
|
| 52 |
System.out.println("Populating Athens transition probs"); |
| 53 |
probs.populate(start, 50000, false); |
| 54 |
probs.populate(B, 50000, false); |
| 55 |
} |
| 56 |
|
| 57 |
public void paintComponent(Graphics g) { |
| 58 |
|
| 59 |
System.out.println("entering paintComponent()"); |
| 60 |
|
| 61 |
computeScales(); |
| 62 |
|
| 63 |
Graphics2D g2d = (Graphics2D) g; |
| 64 |
|
| 65 |
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| 66 |
|
| 67 |
g2d.setStroke(new BasicStroke(1.5f)); |
| 68 |
|
| 69 |
int sx1 = probs.x(start.getX()); |
| 70 |
int sy1 = probs.y(start.getY()); |
| 71 |
int sx2 = probs.x(B.getX()); |
| 72 |
int sy2 = probs.y(B.getY()); |
| 73 |
int t = 49; |
| 74 |
|
| 75 |
AffineTransform transform = getFullTransform(); |
| 76 |
|
| 77 |
double maxProb = 0.0; |
| 78 |
double[][] p = new double[probs.latticeWidth][probs.latticeHeight]; |
| 79 |
for (int i = 0; i < probs.latticeWidth; i++) { |
| 80 |
for (int j = 0; j < probs.latticeHeight; j++) { |
| 81 |
|
| 82 |
p[i][j] = probs.p(sx1, sy1, i, j, t) * probs.p(sx2, sy2, i, j, t); |
| 83 |
if (p[i][j] > maxProb) maxProb = p[i][j]; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
System.out.println("Painting lattice probs"); |
| 88 |
for (int i = 0; i < probs.latticeWidth; i++) { |
| 89 |
for (int j = 0; j < probs.latticeHeight; j++) { |
| 90 |
|
| 91 |
p[i][j] /= maxProb; |
| 92 |
|
| 93 |
Rectangle2D rect = new Rectangle2D.Double(i * probs.dx + probs.minx, j * probs.dy + probs.miny, probs.dx, probs.dy); |
| 94 |
|
| 95 |
g.setColor(cf.getColor((float) p[i][j])); |
| 96 |
g2d.fill(transform.createTransformedShape(rect)); |
| 97 |
g.setColor(Color.black); |
| 98 |
g2d.draw(transform.createTransformedShape(rect)); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
System.out.println("Painting shapes"); |
| 103 |
for (Shape s : shapes) { |
| 104 |
System.out.print("."); |
| 105 |
System.out.flush(); |
| 106 |
GeneralPath path = new GeneralPath(s); |
| 107 |
path.transform(transform); |
| 108 |
g2d.setPaint(Color.BLACK); |
| 109 |
g2d.fill(path); |
| 110 |
} |
| 111 |
|
| 112 |
g2d.setColor(Color.yellow); |
| 113 |
SpaceTime.paintDot(new SpaceTime(0, start), 4, transform, g2d); |
| 114 |
SpaceTime.paintDot(new SpaceTime(0, B), 4, transform, g2d); |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
public static void main(String[] args) { |
| 119 |
|
| 120 |
JFrame frame = new JFrame("Europe"); |
| 121 |
frame.getContentPane().add(BorderLayout.CENTER, new VisualizeKMLJointProb(args[0])); |
| 122 |
frame.setSize(900, 900); |
| 123 |
frame.setVisible(true); |
| 124 |
} |
| 125 |
|
| 126 |
} |