Exemplo n.º 1
0
  public void paintView() {
    if (simple != null) simple.fill(MyColor.cLIGHTGRAY);

    Editor.render();
    // T.show(traceHull);

    COper3.dbPaint();

    if (traceHullPt != null) {
      renderHull(traceHullPt);
    }

    T.show(possHull, MyColor.cDARKGREEN, STRK_THICK, -1);
    T.show(valleyTri, MyColor.cDARKGREEN, STRK_RUBBERBAND, -1);
    T.show(traceValley, null, -1, -1);
    T.show(focusPt, MyColor.cRED, -1, MARK_DISC);
  }
Exemplo n.º 2
0
  public void runAlgorithm() {
    //  traceHull = null;
    COper3.dbClear();

    traceHullPt = null;
    traceValley = null;
    simple = null;
    focusPt = null;
    possHull = null;
    valleyTri = null;
    PtEntry.resetIds();

    EdPolygon[] rgn = UHullMain.getPolygons();

    if (rgn.length < 2) return;

    if (C.vb(OLDALG)) {
      T.disable();
      simple = PossHullOper.buildPossibleHull(rgn);
      T.enable();
    }

    possHull = calcPHullRange(rgn, 0, rgn.length - 1);
  }
Exemplo n.º 3
0
  private static void OLDexpandHull(
      PtEntry convHullEntry, PtEntry aHull, PtEntry bHull, boolean ccw) {
    boolean db__OLD = C.vb(DB_HULLEXPAND);
    if (db__OLD && T.update()) T.msg("expandHull" + T.show(convHullEntry) + " ccw=" + ccw);

    PtEntry[] opp = new PtEntry[2];
    opp[0] = aHull;
    opp[1] = bHull;

    PtEntry old____hEnt = convHullEntry;
    boolean advanced = false;
    do {
      if (old____hEnt != convHullEntry) advanced = true;
      inf.update();
      if (old____hEnt.source() == null) {
        if (db__OLD && T.update())
          T.msg("expandHull, source unknown, guaranteed not convex" + T.show(old____hEnt));
        old____hEnt = old____hEnt.next(ccw);
        continue;
      }

      int w = (old____hEnt.source() == opp[0].source()) ? 1 : 0;
      PtEntry oppEnt = opp[w];

      boolean isTangent =
          !COper3.right(old____hEnt, oppEnt, oppEnt.next(true), ccw)
              && !COper3.right(old____hEnt, oppEnt, oppEnt.prev(true), ccw);

      if (!isTangent) {
        if (db__OLD && T.update())
          T.msg(
              "expandHull, advance tangent line"
                  + T.show(oppEnt.toPolygon(), MyColor.cDARKGRAY, -1, MARK_X)
                  + T.show(old____hEnt)
                  + tl(old____hEnt, oppEnt));
        opp[w] = oppEnt.next(ccw);
        continue;
      }

      if (COper3.left(old____hEnt, oppEnt, old____hEnt.next(ccw), ccw)
          && COper3.left(old____hEnt, oppEnt, old____hEnt.prev(ccw), ccw)) {
        DArray dispPts = new DArray();

        // delete points until cross tangent line
        PtEntry next = old____hEnt.next(ccw);
        while (true) {
          PtEntry prev = next;
          dispPts.add(prev);
          next = prev.delete(ccw);

          inf.update();
          if (COper3.right(old____hEnt, oppEnt, next, ccw)) {
            FPoint2 cross = MyMath.linesIntersection(old____hEnt, oppEnt, prev, next, null);
            old____hEnt = old____hEnt.insert(new PtEntry(cross), ccw);
            if (db__OLD && T.update())
              T.msg(
                  "expandHull, clipped to shadow region"
                      + tl(old____hEnt, oppEnt)
                      + T.show(old____hEnt)
                      + T.show(dispPts));
            break;
          }
        }
      } else {
        if (db__OLD && T.update())
          T.msg(
              "expandHull, not dipping into shadow region"
                  + T.show(old____hEnt.next(ccw))
                  + tl(old____hEnt, oppEnt));
      }
      old____hEnt = old____hEnt.next(ccw);
    } while (!advanced || old____hEnt != convHullEntry);
  }
Exemplo n.º 4
0
  private static void insertValleys(
      PtEntry hullPt, Object aSrc, Object bSrc) { // pa, MyPolygon pb) {
    boolean db = C.vb(DB_INSERTVALLEY);
    PtEntry ent = hullPt;

    if (db && T.update()) T.msg("insertValleys");
    do {
      PtEntry next = ent.next(true);

      if (ent.source() == next.source()) {
        PtEntry orig = ent.orig();

        if (orig.next(true) != next.orig()) {

          PtEntry vPeak0 = ent;
          PtEntry vPeak1 = next;

          EdPolygon opp = (EdPolygon) (vPeak0.source() == aSrc ? bSrc : aSrc);

          FPoint2 kernelPt = opp.getPointMod(C.vi(KERNELVERT));

          // construct a chain from the vertices of the valley
          PtEntry handle = new PtEntry(vPeak0);
          PtEntry hNext = handle;
          PtEntry e = vPeak0.orig();
          while (e != vPeak1.orig()) {
            inf.update();
            e = e.next(true);
            hNext = hNext.insert(new PtEntry(e), true);
          }

          if (C.vb(SKIPCONTOUR)) {
            PtEntry h0 = handle.next(true);
            PtEntry h1 = hNext.prev(true);
            PtEntry.join(vPeak0, h0);
            PtEntry.join(h1, vPeak1);
            if (db && T.update())
              T.msg("inserted unmodified valley" + T.show(vPeak0) + T.show(vPeak1));

          } else {
            if (!C.vb(DB_CONTOUR)) T.disable();
            PtEntry hull = COper3.buildHullForChain(handle, kernelPt);
            if (!C.vb(DB_CONTOUR)) T.enable();
            // find entries corresponding to start, end of hull
            PtEntry peak0 = null, peak1 = null;
            {
              PtEntry hEnt = hull;
              while (peak0 == null || peak1 == null) {
                inf.update();
                if (hEnt.orig() == vPeak0.orig()) peak0 = hEnt;
                if (hEnt.orig() == vPeak1.orig()) peak1 = hEnt;
                hEnt = hEnt.next(true);
              }
            }
            PtEntry.join(vPeak0, peak0.next(true));
            PtEntry.join(peak1.prev(true), vPeak1);
            if (db && T.update())
              T.msg("inserted monotonic valley" + T.show(vPeak0) + T.show(vPeak1));
          }
        }
      }
      ent = next;
    } while (ent != hullPt);
  }
Exemplo n.º 5
0
  /**
   * Apply hull expansion procedure
   *
   * @param convHullEntry an entry of the hull (should be on the convex hull, so it is not deleted
   *     or replaced and is still valid for subsequent calls)
   * @param aHull entry on convex hull of polygon A
   * @param bHull entry on convex hull of polygon B
   * @param ccw true to move in ccw direction, else cw
   */
  private static void expandHull(PtEntry convHullEntry, PtEntry aHull, PtEntry bHull, boolean ccw) {
    if (C.vb(OLDMETHOD)) {
      OLDexpandHull(convHullEntry, aHull, bHull, ccw);
      return;
    }
    boolean db = C.vb(DB_HULLEXPAND);

    if (db && T.update()) T.msg("expandHull" + T.show(convHullEntry) + " ccw=" + ccw);

    // tangent points for A, B
    PtEntry[] tangentPoints = new PtEntry[2];
    tangentPoints[0] = aHull;
    tangentPoints[1] = bHull;

    PtEntry hEnt = convHullEntry;
    do {
      inf.update();

      // calculate tangent ray R
      PtEntry tangentPt = null;
      while (true) {
        int tanIndex = (hEnt.source() == tangentPoints[0].source()) ? 1 : 0;
        tangentPt = tangentPoints[tanIndex];

        if (!COper3.right(hEnt, tangentPt, tangentPt.next(true), ccw)
            && !COper3.right(hEnt, tangentPt, tangentPt.prev(true), ccw)) break;

        tangentPt = tangentPt.next(ccw);

        if (db && T.update())
          T.msg(
              "expandHull, advance tangent line"
                  + T.show(tangentPt.toPolygon(), MyColor.cDARKGRAY, -1, MARK_DISC)
                  + T.show(hEnt)
                  + tl(hEnt, tangentPt));
        tangentPoints[tanIndex] = tangentPt;
      }

      if (COper3.left(hEnt, tangentPt, hEnt.next(ccw), ccw)) {
        DArray dispPts = new DArray();

        // delete points until cross tangent line
        PtEntry next = hEnt.next(ccw);
        while (true) {
          PtEntry prev = next;
          dispPts.add(prev);
          next = prev.delete(ccw);
          if (COper3.right(hEnt, tangentPt, next, ccw)) {
            FPoint2 cross = MyMath.linesIntersection(hEnt, tangentPt, prev, next, null);
            hEnt = hEnt.insert(new PtEntry(cross), ccw);
            if (db && T.update())
              T.msg(
                  "expandHull, clipped to shadow region"
                      + tl(hEnt, tangentPt)
                      + T.show(hEnt)
                      + T.show(dispPts));
            break;
          }
        }
      } else {
        if (db && T.update())
          T.msg(
              "expandHull, not dipping into shadow region"
                  + T.show(hEnt.next(ccw))
                  + tl(hEnt, tangentPt));
      }
      while (true) {
        hEnt = hEnt.next(ccw);
        if (COper3.left(hEnt.prev(ccw), hEnt, hEnt.next(ccw), ccw)) break;
        if (db && T.update()) T.msg("skipping reflex vertex" + T.show(hEnt));
      }
    } while (hEnt != convHullEntry);
  }