From 74cd347644b95c470c2b1ece5e303180a9e5e641 Mon Sep 17 00:00:00 2001 From: JimmyBoivie Date: Sun, 6 Dec 2015 00:12:06 -0500 Subject: [PATCH] Fixed bugs - I think it is good --- main/CompGeo.pde | 41 +++++++++++++++++++++---------- main/DrawHalfEdge.pde | 4 ++-- main/Face.pde | 52 +++++++++++----------------------------- main/HalfEdge.pde | 22 +++++++++++++++++ main/PointList.pde | 1 + main/main.pde | 56 +++++++++++++++++++++++++++++++++++-------- 6 files changed, 114 insertions(+), 62 deletions(-) diff --git a/main/CompGeo.pde b/main/CompGeo.pde index 5215dff..f843bb2 100644 --- a/main/CompGeo.pde +++ b/main/CompGeo.pde @@ -75,23 +75,24 @@ public static class CompGeo { - - public static ArrayList findFriends(HalfEdge inner, HalfEdge outer, PointList points) { + public static ArrayList findFriends(HalfEdge outer, PointList points) { ArrayList handles = points.getAllStructures(); ArrayList friends = new ArrayList(); int num = handles.size(); HalfEdge out = null; for (int i = 0; i < num; i++) { - if (inner.canReach(handles.get(i))) { continue; } + //if (inner.canReach(handles.get(i))) { friends.add(inner); continue; } out = findTightOuterBoundary(handles.get(i), points); if (out == outer) { - if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; } - else { friends.add(handles.get(i)); continue; } + //if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; } + //else { friends.add(handles.get(i)); continue; } + friends.add(findCWR(handles.get(i))); continue; } if ((out != null) && (outer != null)) { - if (out.canReach(outer)) { - if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; } - else { friends.add(handles.get(i)); continue; } + if (out.canReachNext(outer)) { + //if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; } + //else { friends.add(handles.get(i)); continue; } + friends.add(findCWR(handles.get(i))); continue; } } } @@ -118,8 +119,8 @@ public static class CompGeo { } } } - tightest = findSuperTightBoundary(inner, tightest, far); - tightest.reset(); + tightest = findSuperTightBoundary(inner, tightest, far); + if (tightest != null) { tightest.reset(); } return tightest; } @@ -138,7 +139,23 @@ public static class CompGeo { return null; } + public static HalfEdge findCWR(HalfEdge ref) { + HalfEdge out = findClockWiseRepresentation(ref); + ref.reset(); + return out; + } - - + private static HalfEdge findClockWiseRepresentation(HalfEdge ref) { + if (signedArea(ref) >= 0) { return ref; } + if (ref.getCounted() == false) { + ref.setCounted(true); + HalfEdge temp = findClockWiseRepresentation(ref.getnext()); + if (temp != null) { return temp; } + temp = findClockWiseRepresentation(ref.getprevious()); + if (temp != null) { return temp; } + temp = findClockWiseRepresentation(ref.gettwin()); + if (temp != null) { return temp; } + } + return null; + } } \ No newline at end of file diff --git a/main/DrawHalfEdge.pde b/main/DrawHalfEdge.pde index 7bc0a88..0054680 100644 --- a/main/DrawHalfEdge.pde +++ b/main/DrawHalfEdge.pde @@ -1,7 +1,7 @@ public class DrawHalfEdge { public void drawline(Point v1, Point v2) { - System.out.println(v1 + " " + v2); + //System.out.println(v1 + " " + v2); line(v1.getX(), v1.getY(), v2.getX(), v2.getY()); } public void drawpoint(Point v) { @@ -18,7 +18,7 @@ public class DrawHalfEdge { public void drawConnectedGraph(Point p) { ArrayList edges = p.getLeaving(); drawpoint(p); - System.out.println(p); + //System.out.println(p); if(edges != null) { for(HalfEdge edge: edges) { //System.out.println(edge); diff --git a/main/Face.pde b/main/Face.pde index c118812..63aefce 100644 --- a/main/Face.pde +++ b/main/Face.pde @@ -3,47 +3,23 @@ public class Face { HalfEdge outerComponent; ArrayList innerComponents; - public Face(HalfEdge outer) { - outerComponent = outer; - innerComponents = new ArrayList(); + public Face(HalfEdge ref, PointList points) { + if (CompGeo.signedArea(ref) < 0) { outerComponent = ref; } + else { outerComponent = CompGeo.findTightOuterBoundary(ref, points); } + innerComponents = CompGeo.findFriends(outerComponent, points); } - public void setOuterComponent(HalfEdge he) { - outerComponent = he; - } - - public HalfEdge getOuterComponent() { - return outerComponent; - } - - public void addInnerComponent(HalfEdge he) { - innerComponents.add(he); - } - - public void removeInnerComponent(HalfEdge he) { - innerComponents.remove(he); - } - - public void updateReference(HalfEdge he) { - for (HalfEdge h: innerComponents) { - if (he.isEventuallyNext(h)) { - removeInnerComponent(h); - } + public void printFace() { + System.out.println("Outer Face:"); + if (outerComponent != null) { outerComponent.printRNext(); } + System.out.println(); + System.out.println("Inner Components:"); + int num = innerComponents.size(); + for (int i = 0; i < num; i++) { + System.out.println("COMPONENT[" + i + "]"); + innerComponents.get(i).printRNext(); } - addInnerComponent(he); - } - - - public ArrayList getInnerComponents() { - return innerComponents; + System.out.println(); } - // NEED METHODS - // MERGE: MERGE TWO FACES - // BREAK: BREAKS FACE INTO TWO - // INSIDE: CHECK IF POINT IS INSIDE A FACE???? - - - // MAYBE ASSUME OUTTER FACE IS IMPLICIT??? - } \ No newline at end of file diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index 3ba5311..01e8e09 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -261,12 +261,25 @@ public class HalfEdge { } return false; } + private boolean isReachableNext(HalfEdge h) { + if (this == h) { return true; } + if (counted == false) { + counted = true; + return next.isReachableNext(h); + } + return false; + } public boolean canReach(HalfEdge h) { boolean out = isReachable(h); reset(); return out; } + public boolean canReachNext(HalfEdge h) { + boolean out = isReachableNext(h); + reset(); + return out; + } // may not want getters, but for now they are here. @@ -324,4 +337,13 @@ public class HalfEdge { incidentFace = f; } + public void printRNext() { + System.out.println(" " + origin); + HalfEdge temp = next; + while (temp != this) { + System.out.println(" " + temp.getOrigin()); + temp = temp.getnext(); + } + } + } \ No newline at end of file diff --git a/main/PointList.pde b/main/PointList.pde index 2d7e9c8..a0676ef 100644 --- a/main/PointList.pde +++ b/main/PointList.pde @@ -37,6 +37,7 @@ public class PointList { int num = points.size(); ArrayList struct = new ArrayList(); for (int i = 0; i < num; i++) { + if (points.get(i).getRef() == null) { continue; } if (points.get(i).getRef().getCounted() == false) { points.get(i).getRef().count(); struct.add(points.get(i).getRef()); diff --git a/main/main.pde b/main/main.pde index 064adf0..37df552 100644 --- a/main/main.pde +++ b/main/main.pde @@ -18,7 +18,28 @@ public void setup() { list.addPoint(p5); Point p6 = new Point (-20, -40); list.addPoint(p6); - Point p7 = new Point (10000,10000); + Point p7 = new Point(-50, 0); + list.addPoint(p7); + Point p8 = new Point(-100, 0); + list.addPoint(p8); + Point p9 = new Point(-100, 35); + list.addPoint(p9); + Point p10 = new Point(-50, 35); + list.addPoint(p10); + Point p11 = new Point(-80, 15); + list.addPoint(p11); + Point p12 = new Point(-60, 25); + list.addPoint(p12); + Point p13 = new Point (-25, 25); + list.addPoint(p13); + Point p14 = new Point (-25, 100); + list.addPoint(p14); + Point p15 = new Point(-150, -20); + list.addPoint(p15); + Point p16 = new Point (20, 50); + list.addPoint(p16); + Point p17 = new Point (20, 100); + list.addPoint(p17); DrawHalfEdge draw = new DrawHalfEdge(); HalfEdge h1 = new HalfEdge(p1, p2); HalfEdge h2 = new HalfEdge(p1, p4); @@ -26,15 +47,27 @@ public void setup() { HalfEdge h4 = new HalfEdge(p1, p5); HalfEdge h5 = new HalfEdge(p3, p4); HalfEdge h6 = new HalfEdge(p2, p4); - float f = CompGeo.signedArea(h1.gettwin()); - float f2 = CompGeo.signedArea(h1); - System.out.println("Signed Area: " + f); - System.out.println("Signed Area: " + f2); - h1.gettwin().printFace(); - h1.printFace(); - if (CompGeo.inside(h1.gettwin(), p6, p7)) { - System.out.println("INSIDE"); - } else { System.out.println("OUTSIDE"); } + HalfEdge h7 = new HalfEdge(p7, p8); + HalfEdge h8 = new HalfEdge(p8, p9); + HalfEdge h9 = new HalfEdge(p9, p10); + HalfEdge h10 = new HalfEdge(p10, p7); + HalfEdge h11 = new HalfEdge(p11,p12); + HalfEdge h12 = new HalfEdge(p13,p14); + HalfEdge h13 = new HalfEdge(p7, p15); + HalfEdge h14 = new HalfEdge(p8, p15); + HalfEdge h15 = new HalfEdge(p9, p15); + HalfEdge h16 = new HalfEdge(p16, p17); + + //h1.printFace(); + //float f = CompGeo.signedArea(h1.gettwin()); + //float f2 = CompGeo.signedArea(h1); + //System.out.println("Signed Area: " + f); + //System.out.println("Signed Area: " + f2); + //h1.gettwin().printFace(); + //h1.printFace(); + //if (CompGeo.inside(h1.gettwin(), p6, p7)) { + // System.out.println("INSIDE"); + //} else { System.out.println("OUTSIDE"); } //HalfEdge h5 = new HalfEdge(p5, p2); //h5.gettwin().printFace(); //h5.printFace(); @@ -49,6 +82,9 @@ public void setup() { //HalfEdge h5 = new HalfEdge(v1,v2); //h1.facePrint(); draw.drawGraph(list.getPoints()); + //(new Face(h4, list)).printFace(); + (new Face(h12, list)).printFace(); + } /*public void draw() { fill(0,0,255,40);