summaryrefslogtreecommitdiffstats
path: root/voronoiTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'voronoiTest.java')
-rw-r--r--voronoiTest.java222
1 files changed, 222 insertions, 0 deletions
diff --git a/voronoiTest.java b/voronoiTest.java
new file mode 100644
index 0000000..0fdb4f1
--- /dev/null
+++ b/voronoiTest.java
@@ -0,0 +1,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
+
+ }
+}