summaryrefslogtreecommitdiffstats
path: root/voronoiTest.java
blob: 0fdb4f1bc3a47202489bac6d8d8b8b63ab8b8884 (plain) (blame)
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
import helper.ListBTS;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import voronoi.voronoi;
import DataStructure.GSMMap;
import Parse.NMEAParse;
import Parse.sqlreader;

public class voronoiTest extends Frame {
	static voronoi vTest = new voronoi();
	static GSMMap map;
	static int arfcn;
	static int zoom;
	private int x = 272;
	private int y = 136;
	private int xmouse = 0;
	private int ymouse = 0;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */

	public static void main(String[] args) throws ClassNotFoundException,
			SQLException, IOException { // TODO Auto-generated method stub
		// sqlreader sql = new sqlreader(new NMEAParse("campus1.log"),
		// 262026003662195l, 3000l);
		sqlreader sql = new sqlreader(new NMEAParse("nachGPN.log"),
				262026003662195l, 3000l);
		map = new GSMMap(sql, 0.00004);
		map.average();
		map.removeOutlier();
		// GoogleOut average = new GoogleOut(map, "average-all.kml");

		vTest = new voronoi();
		// vTest.sortNode(map, map.getUniqueBTSlist()[0].ARFCN,10);
		arfcn = 877;
		zoom = 10;
		vTest.sortNode(map, arfcn, zoom, 20, 20);
		vTest.generateVoronoi(0, 1500, 0, 1500);
		voronoiTest zeichnedass = new voronoiTest();
		zeichnedass.setVisible(true);
	}

	public voronoiTest() {
		setSize(750, 750);
		addWindowListener(new closeFrame());// funktioniert, weil die Klasse von
											// Frame erbt
		addMouseListener(new mouse());
	}

	public void paint(Graphics gr) {
		Graphics2D g = (Graphics2D) gr;
		vTest.DrawVor(g);
		g.setColor(Color.black);
		/*
		 * //draws the points in gsmmap for (int x = 0; x < map.Xcoords.length;
		 * x++) { for (int y = 0; y < map.Ycoords.length; y++) { if
		 * (ListBTS.contains(map.map[x][y], arfcn)) { // Punkte zeichnen
		 * g.drawRect(x * zoom - 1, y * zoom - 1, 2, 2); }
		 * 
		 * } }
		 */
		g.setColor(Color.magenta);
		Path2D test = vTest.getPoly(x, y);
		if (test != null) {

			g.fill(vTest.getPoly(x, y));
			Path2D poly = vTest.getPoly(x, y);
			System.out.println("Polygon: ");
			PathIterator itr = poly.getPathIterator(null);
			System.out.println("");
			while (!itr.isDone()) {
				double[] result = new double[6];
				itr.currentSegment(result);
				System.out.print(result[0] + "," + result[1] + " ");
				itr.next();
			}
			System.out.println("");

			// for (int i = 0; i < poly.npoints; i++) {
			// System.out.print(poly.xpoints[i] + "," + poly.ypoints[i] + " ");
			// }
			// show neighbors
			ArrayList<Point2D> neigh = vTest.getDirectNeighbors(x, y);
			for (int i = 0; i < neigh.size(); i++) {
				g.setColor(Color.green);
				g.fillRect((int) neigh.get(i).getX(),
						(int) neigh.get(i).getY(), 2, 2);
			}
			g.fillRect(160, 160, 5, 5);
			System.out.println("");
			System.out.println("Mouse in polygon: " + poly.contains(x, y));
			System.out.println("Fläche: " + vTest.area(poly));
		} else
			System.out.println("Null-Polygon;");
		g.setColor(Color.black);
		for (int x = 0; x < map.Xcoords.length; x++) {
			for (int y = 0; y < map.Ycoords.length; y++) {
				if (ListBTS.contains(map.map[x][y], arfcn)) {
					g.drawRect(x * zoom - 1, y * zoom - 1, 3, 3);
				}
			}
		}

		// draw cut with new voronoi
		voronoi voronoi2 = new voronoi();
		voronoi2.sortNode(map, arfcn, zoom, xmouse / zoom, ymouse / zoom);
		voronoi2.generateVoronoi(0, 2000, 0, 2000);
		g.setColor(Color.gray);
		Point2D mouse = voronoi2.getNearestPoint(xmouse, ymouse);
		Path2D interpolationPoly = voronoi2.getPoly((int) mouse.getX(),
				(int) mouse.getY());
		g.draw(interpolationPoly);
		// show neighbors of voronoi2
		ArrayList<Point2D> neigh2 = voronoi2.getDirectNeighbors(mouse.getX(),
				mouse.getY());
		g.drawOval((int) mouse.getX(), (int) mouse.getY(), 3, 3);

		for (Point2D currneigh2 : neigh2) {
			g.fillRect((int) currneigh2.getX() - 2,
					(int) currneigh2.getY() - 2, 5, 5);
			// fill cut with Color
			// vTest.drawIntersectArea(
			// interpolationPoly,
			// vTest.getPoly((int) currneigh2.getX(),
			// (int) currneigh2.getY()), g);

		}

	}

	public Dimension getPreferredSize() {
		return new Dimension(300, 500);
	}

	public void processMouseEvent(MouseEvent e) {
		if (e.getID() == MouseEvent.MOUSE_CLICKED
				&& e.getButton() == MouseEvent.BUTTON1) {
			System.out.println("Maus bei:" + e.getX() + "," + e.getY());
			Point2D mouse = vTest.getNearestPoint(e.getX(), e.getY());
			x = (int) mouse.getX();
			y = (int) mouse.getY();
			xmouse = (int) e.getX();
			ymouse = (int) e.getY();

			System.out.println("Maustreffer bei: " + x + "," + y);
			repaint();
		}
	}

}

/**
 * Diese Klasse ist ein WindowsAdapter. Dieser kann auf WindowsEvents hören.
 * Automatisch wird dann windowsClosing ausgeführt
 * 
 * @author richy
 * 
 */
class closeFrame extends WindowAdapter {
	public void windowClosing(WindowEvent e) {
		System.exit(0);
	}
}

class mouse implements MouseListener {
	public void processMouseEvent(MouseEvent e) {
		System.out.println("bla");
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}
}