Example #1
0
 public void dispose() {
   int i, n;
   if (_sites != null) {
     _sites.dispose();
     _sites = null;
   }
   if (_triangles != null) {
     n = _triangles.size();
     for (i = 0; i < n; ++i) {
       _triangles.get(i).dispose();
     }
     _triangles.clear();
     _triangles = null;
   }
   if (_edges != null) {
     n = _edges.size();
     for (i = 0; i < n; ++i) {
       _edges.get(i).dispose();
     }
     _edges.clear();
     _edges = null;
   }
   _plotBounds = null;
   _sitesIndexedByLocation = null;
 }
Example #2
0
  private void fortunesAlgorithm() {
    Site newSite, bottomSite, topSite, tempSite;
    Vertex v, vertex;
    Point newintstar = null;
    LR leftRight;
    Halfedge lbnd, rbnd, llbnd, rrbnd, bisector;
    Edge edge;

    Rectangle dataBounds = _sites.getSitesBounds();

    int sqrt_nsites = (int) Math.sqrt(_sites.get_length() + 4);
    HalfedgePriorityQueue heap =
        new HalfedgePriorityQueue(dataBounds.y, dataBounds.height, sqrt_nsites);
    EdgeList edgeList = new EdgeList(dataBounds.x, dataBounds.width, sqrt_nsites);
    ArrayList<Halfedge> halfEdges = new ArrayList();
    ArrayList<Vertex> vertices = new ArrayList();

    Site bottomMostSite = _sites.next();
    newSite = _sites.next();

    for (; ; ) {
      if (heap.empty() == false) {
        newintstar = heap.min();
      }

      if (newSite != null && (heap.empty() || compareByYThenX(newSite, newintstar) < 0)) {
        /* new site is smallest */
        // trace("smallest: new site " + newSite);

        // Step 8:
        lbnd =
            edgeList.edgeListLeftNeighbor(
                newSite.get_coord()); // the Halfedge just to the left of newSite
        // trace("lbnd: " + lbnd);
        rbnd = lbnd.edgeListRightNeighbor; // the Halfedge just to the right
        // trace("rbnd: " + rbnd);
        bottomSite = rightRegion(lbnd, bottomMostSite); // this is the same as leftRegion(rbnd)
        // this Site determines the region containing the new site
        // trace("new Site is in region of existing site: " + bottomSite);

        // Step 9:
        edge = Edge.createBisectingEdge(bottomSite, newSite);
        // trace("new edge: " + edge);
        _edges.add(edge);

        bisector = Halfedge.create(edge, LR.LEFT);
        halfEdges.add(bisector);
        // inserting two Halfedges into edgeList constitutes Step 10:
        // insert bisector to the right of lbnd:
        edgeList.insert(lbnd, bisector);

        // first half of Step 11:
        if ((vertex = Vertex.intersect(lbnd, bisector)) != null) {
          vertices.add(vertex);
          heap.remove(lbnd);
          lbnd.vertex = vertex;
          lbnd.ystar = vertex.get_y() + newSite.dist(vertex);
          heap.insert(lbnd);
        }

        lbnd = bisector;
        bisector = Halfedge.create(edge, LR.RIGHT);
        halfEdges.add(bisector);
        // second Halfedge for Step 10:
        // insert bisector to the right of lbnd:
        edgeList.insert(lbnd, bisector);

        // second half of Step 11:
        if ((vertex = Vertex.intersect(bisector, rbnd)) != null) {
          vertices.add(vertex);
          bisector.vertex = vertex;
          bisector.ystar = vertex.get_y() + newSite.dist(vertex);
          heap.insert(bisector);
        }

        newSite = _sites.next();
      } else if (heap.empty() == false) {
        /* intersection is smallest */
        lbnd = heap.extractMin();
        llbnd = lbnd.edgeListLeftNeighbor;
        rbnd = lbnd.edgeListRightNeighbor;
        rrbnd = rbnd.edgeListRightNeighbor;
        bottomSite = leftRegion(lbnd, bottomMostSite);
        topSite = rightRegion(rbnd, bottomMostSite);
        // these three sites define a Delaunay triangle
        // (not actually using these for anything...)
        // _triangles.push(new Triangle(bottomSite, topSite, rightRegion(lbnd)));

        v = lbnd.vertex;
        v.setIndex();
        lbnd.edge.setVertex(lbnd.leftRight, v);
        rbnd.edge.setVertex(rbnd.leftRight, v);
        edgeList.remove(lbnd);
        heap.remove(rbnd);
        edgeList.remove(rbnd);
        leftRight = LR.LEFT;
        if (bottomSite.get_y() > topSite.get_y()) {
          tempSite = bottomSite;
          bottomSite = topSite;
          topSite = tempSite;
          leftRight = LR.RIGHT;
        }
        edge = Edge.createBisectingEdge(bottomSite, topSite);
        _edges.add(edge);
        bisector = Halfedge.create(edge, leftRight);
        halfEdges.add(bisector);
        edgeList.insert(llbnd, bisector);
        edge.setVertex(LR.other(leftRight), v);
        if ((vertex = Vertex.intersect(llbnd, bisector)) != null) {
          vertices.add(vertex);
          heap.remove(llbnd);
          llbnd.vertex = vertex;
          llbnd.ystar = vertex.get_y() + bottomSite.dist(vertex);
          heap.insert(llbnd);
        }
        if ((vertex = Vertex.intersect(bisector, rrbnd)) != null) {
          vertices.add(vertex);
          bisector.vertex = vertex;
          bisector.ystar = vertex.get_y() + bottomSite.dist(vertex);
          heap.insert(bisector);
        }
      } else {
        break;
      }
    }

    // heap should be empty now
    heap.dispose();
    edgeList.dispose();

    for (Halfedge halfEdge : halfEdges) {
      halfEdge.reallyDispose();
    }
    halfEdges.clear();

    // we need the vertices to clip the edges
    for (Edge e : _edges) {
      e.clipVertices(_plotBounds);
    }
    // but we don't actually ever use them again!
    for (Vertex v0 : vertices) {
      v0.dispose();
    }
    vertices.clear();
  }
Example #3
0
 /*public Point nearestSitePoint(proximityMap:BitmapData,double x, double y)
 {
 return _sites.nearestSitePoint(proximityMap, x, y);
 }*/
 public ArrayList<Point> siteCoords() {
   return _sites.siteCoords();
 }
Example #4
0
 /*public ArrayList<LineSegment> spanningTree(String type, keepOutMask:BitmapData = null)
 {
 ArrayList<Edge>  edges = selectNonIntersectingEdges(keepOutMask, _edges);
 ArrayList<LineSegment>  segments = delaunayLinesForEdges(edges);
 return kruskal(segments, type);
 }*/
 public ArrayList<ArrayList<Point>> regions() {
   return _sites.regions(_plotBounds);
 }
Example #5
0
 public ArrayList<Circle> circles() {
   return _sites.circles();
 }
Example #6
0
 private void addSite(Point p, Color color, int index) {
   double weight = Math.random() * 100;
   Site site = Site.create(p, index, weight, color);
   _sites.push(site);
   _sitesIndexedByLocation.put(p, site);
 }