diff --git a/main/Face.pde b/main/Face.pde index a454c01..0f9b745 100644 --- a/main/Face.pde +++ b/main/Face.pde @@ -9,17 +9,52 @@ public class Face { innerComponents = CompGeo.findFriends(outerComponent, points); } + public void daColoring(int r, int g, int b, PointList pl, float x, float y) { + Point p = null; + stroke(r,g,b); + for (int i = 0; i < (int)x; i++) { + for (int j = 0; j < (int)y; j++) { + p = new Point(i, j); + if (inSpecificFace(p, pl)) { + point(i,j); + System.out.println(p); + } + } + } + stroke(0); + } + + public boolean inSpecificFace(Point a, PointList pl) { + if ((outerComponent == null) || (CompGeo.inside(outerComponent, a, pl.getFar()))) { + System.out.println(a); + int num = innerComponents.size(); + for (int i = 0; i < num; i++) { + if (inAnInner(innerComponents.get(i), a, pl)) { + return false; + } + } + return true; + } + return false; + } + + public boolean inAnInner(HalfEdge inner, Point a, PointList pl) { + if (CompGeo.signedArea(inner) == 0) { return false; } + if (CompGeo.inside(inner, a, pl.getFar())) { return true; } + return false; + } + public void printFace() { - //System.out.println("Outer Face:"); + System.out.println("Outer Face:"); if (outerComponent != null) { outerComponent.printRNext(); } - //System.out.println(); - //System.out.println("Inner Components:"); + System.out.println(); + System.out.println("Inner Components:"); int num = innerComponents.size(); for (int i = 0; i < num; i++) { - //System.out.println("COMPONENT[" + i + "]"); + System.out.println("COMPONENT[" + i + "]"); innerComponents.get(i).printRNext(); } - //System.out.println(); + System.out.println(); } } diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index 4cbf2ff..3a4a1d2 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -18,7 +18,7 @@ public class HalfEdge { p.setRef(null); q.setRef(null); state = 0; - console.log("CLASS0"); + //console.log("CLASS0"); } else if (p.count() == 1) { p.setRef(null); q.setRef(twin.getAnotherLeaving()); @@ -27,7 +27,7 @@ public class HalfEdge { // NOTHING SPECIAL MUST BE DONE // Make Sure face is not represented by dissapearing edge state = 1; - console.log("CLASS1A"); + //console.log("CLASS1A"); } else if (q.count() == 1) { p.setRef(this.getAnotherLeaving()); q.setRef(null); @@ -36,7 +36,7 @@ public class HalfEdge { // NOTHING SPECIAL MUST BE DONE // Make sure face is not represented by dissapearing edge state = 1; - console.log("CLASS1B"); + //console.log("CLASS1B"); } else { int expected = p.count() - 2; p.setRef(this.getAnotherLeaving()); @@ -45,7 +45,7 @@ public class HalfEdge { twin.getprevious().setnext(this.getnext()); this.getprevious().setnext(twin.getnext()); twin.getnext().setprevious(this.getprevious()); - console.log("CLASS23"); + //console.log("CLASS23"); if (p.count() == expected) { // was not broken faces merge! // @@ -371,10 +371,10 @@ public class HalfEdge { } public void printRNext() { - ////System.out.println(" " + origin); + System.out.println(" " + origin); HalfEdge temp = next; while (temp != this) { - //System.out.println(" " + temp.getOrigin()); + System.out.println(" " + temp.getOrigin()); temp = temp.getnext(); } } diff --git a/main/PointList.pde b/main/PointList.pde index 788589a..3d9e22a 100644 --- a/main/PointList.pde +++ b/main/PointList.pde @@ -52,10 +52,12 @@ public class PointList { } public HalfEdge getHalfEdge(Point p, Point q) { + System.out.println(p); + System.out.println(q); int num = points.size(); int id = -1; for (int i = 0; i < num; i++) { - if (p.equals(points.get(i))) { + if (p == points.get(i)) { id = i; } } diff --git a/main/main.pde b/main/main.pde index 090fe19..3017104 100644 --- a/main/main.pde +++ b/main/main.pde @@ -6,12 +6,13 @@ PointList list = new PointList(); DrawHalfEdge drawgraph = new DrawHalfEdge(); boolean removeEdge = false; Point removeEdgePoint; - +boolean colorEdge = false; +Point colorEdgePoint; +int colorFaceColor = 0; public void setup() { size(800, 500); background(255); - fill(0,0); translate(width/2, height/2); /*Point p1 = new Point(300, 300); list.addPoint(p1); @@ -92,7 +93,7 @@ public void setup() { //(new Face(h12, list)).printFace(); } void draw() { - background(255); + //background(255); drawgraph.drawGraph(list.getPoints()); } void keyPressed() { @@ -131,7 +132,47 @@ void mouseReleased() { case 2: removeEdgeMode(x,y); break; + case 4: + colorFace(x, y); + colorFaceColor = 0; + break; + case 5: + colorFace(x,y); + colorFaceColor = 1; + break; + } +} +public void colorFace(float x, float y) { + if(colorEdge) { + for(Point p: list.getPoints()) { + if((p.getX() - 10 < x) && (p.getX() + 10 > x)) { + if((p.getY() - 10 < y) && (p.getY() + 10 > y)) { + HalfEdge h = list.getHalfEdge(colorEdgePoint, p); + if(h != null) { + System.out.println("h is not null"); + Face f = new Face(h, list); + f.printFace(); + if(colorFaceColor == 0) { + f.daColoring(0,0,255,list, width, height); + } else if(colorFaceColor ==1) { + f.daColoring(0,255,0,list, width, height); + } + } + } + } + } + colorEdge = false; + } else { + for(Point p: list.getPoints()) { + if((p.getX() - 10 < x) && (p.getX() + 10 > x)) { + if((p.getY() - 10 < y) && (p.getY() + 10 > y)) { + colorEdgePoint = p; + colorEdge = true; + } + } + } } + noFill(); } public void insertMode(float x, float y) { if(pointclickedbool) { @@ -180,6 +221,7 @@ public void removePointMode(float x, float y) { } if(removePoint) { list.removePoint(removeThis); + background(255); } } @@ -191,6 +233,7 @@ public void removeEdgeMode(float x, float y) { HalfEdge h = list.getHalfEdge(removeEdgePoint, p); if(h != null) { h.Remove(); + background(255); } removeEdge = false; }