示例#1
0
  @Override
  public void prepareTriangulation(Triangulatable t) {
    super.prepareTriangulation(t);

    double xmax, xmin;
    double ymax, ymin;

    xmax = xmin = _points.get(0).getX();
    ymax = ymin = _points.get(0).getY();
    // Calculate bounds. Should be combined with the sorting
    for (TriangulationPoint p : _points) {
      if (p.getX() > xmax) xmax = p.getX();
      if (p.getX() < xmin) xmin = p.getX();
      if (p.getY() > ymax) ymax = p.getY();
      if (p.getY() < ymin) ymin = p.getY();
    }

    double deltaX = ALPHA * (xmax - xmin);
    double deltaY = ALPHA * (ymax - ymin);
    TPoint p1 = new TPoint(xmax + deltaX, ymin - deltaY);
    TPoint p2 = new TPoint(xmin - deltaX, ymin - deltaY);

    setHead(p1);
    setTail(p2);

    //        long time = System.nanoTime();
    // Sort the points along y-axis
    Collections.sort(_points, _comparator);
    //        logger.info( "Triangulation setup [{}ms]", ( System.nanoTime() - time ) / 1e6 );
  }
示例#2
0
  /** Creates constraints and populates the context with points */
  public void prepareTriangulation(TriangulationContext<?> tcx) {
    if (m_triangles == null) {
      m_triangles = new ArrayList<DelaunayTriangle>(_points.size());
    } else {
      m_triangles.clear();
    }

    // Outer constraints
    for (int i = 0; i < _points.size() - 1; i++) {
      tcx.newConstraint(_points.get(i), _points.get(i + 1));
    }
    tcx.newConstraint(_points.get(0), _points.get(_points.size() - 1));
    tcx.addPoints(_points);

    // Hole constraints
    if (_holes != null) {
      for (Polygon p : _holes) {
        for (int i = 0; i < p._points.size() - 1; i++) {
          tcx.newConstraint(p._points.get(i), p._points.get(i + 1));
        }
        tcx.newConstraint(p._points.get(0), p._points.get(p._points.size() - 1));
        tcx.addPoints(p._points);
      }
    }

    if (_steinerPoints != null) {
      tcx.addPoints(_steinerPoints);
    }
  }
示例#3
0
 public void clear() {
   super.clear();
   _triList.clear();
 }