Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
389 lines (380 sloc) 9.96 KB
boolean pointclickedbool = false;
boolean linedrawn = false;
int mode = 0;
Point pointclicked;
PointList list = new PointList();
DrawHalfEdge drawgraph = new DrawHalfEdge();
boolean removeEdge = false;
Point removeEdgePoint;
boolean colorEdge = false;
Point colorEdgePoint;
int colorFaceColor = 1;
HalfEdge colorFaceHalfEdge;
public void setup() {
size(800, 500);
background(255);
translate(width/2, height/2);
/*Point p1 = new Point(300, 300);
list.addPoint(p1);
Point p2 = new Point(400, 350);
list.addPoint(p2);
Point p3 = new Point(100, 250);
list.addPoint(p3);
Point p4 = new Point(300, 450);
list.addPoint(p4);
Point p5 = new Point(500, 300);
list.addPoint(p5);
Point p6 = new Point (280, 260);
list.addPoint(p6);
Point p7 = new Point(250, 300);
list.addPoint(p7);
Point p8 = new Point(200, 300);
list.addPoint(p8);
Point p9 = new Point(200, 335);
list.addPoint(p9);
Point p10 = new Point(250, 335);
list.addPoint(p10);
Point p11 = new Point(200, 315);
list.addPoint(p11);
Point p12 = new Point(240, 325);
list.addPoint(p12);
Point p13 = new Point (275, 325);
list.addPoint(p13);
Point p14 = new Point (275, 400);
list.addPoint(p14);
Point p15 = new Point(150, 280);
list.addPoint(p15);
Point p16 = new Point (320, 350);
list.addPoint(p16);
Point p17 = new Point (320, 400);
list.addPoint(p17);
HalfEdge h1 = new HalfEdge(p1, p2);
HalfEdge h2 = new HalfEdge(p1, p4);
HalfEdge h3 = new HalfEdge(p3, p1);
HalfEdge h4 = new HalfEdge(p1, p5);
HalfEdge h5 = new HalfEdge(p3, p4);
HalfEdge h6 = new HalfEdge(p2, p4);
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();
//HalfEdge h1 = new HalfEdge(v, v1);
//h1.facePrint();
//HalfEdge h2 = new HalfEdge(v, v3);
//h1.facePrint();
//HalfEdge h3 = new HalfEdge(v, v2);
//h1.facePrint();
//HalfEdge h4 = new HalfEdge(v,v4);
//h1.facePrint();
//HalfEdge h5 = new HalfEdge(v1,v2);
//h1.facePrint();
//drawgraph.drawGraph(list.getPoints());
//(new Face(h4, list)).printFace();
//(new Face(h12, list)).printFace();
}
void draw() {
if(mode != 4) {
background(255);
}
drawgraph.drawGraph(list.getPoints());
if(pointclickedbool) {
line(pointclicked.getX(), pointclicked.getY(), mouseX,mouseY);
}
}
void keyPressed() {
switch (key) {
case 'i':
mode = 0;
break;
case 'r':
mode = 1;
break;
case 'e':
mode = 2;
break;
case 'p':
mode = 3;
break;
case 'c':
mode = 4;
break;
case '0':
colorFaceColor = 0;
break;
case '1':
colorFaceColor = 1;
break;
case '2':
colorFaceColor = 2;
break;
case '3':
colorFaceColor = 3;
break;
case '4':
colorFaceColor = 4;
break;
case '5':
colorFaceColor = 5;
break;
case '6':
colorFaceColor = 6;
break;
case '7':
colorFaceColor = 7;
break;
case '8':
colorFaceColor = 8;
break;
case '9':
colorFaceColor = 9;
break;
case 'w':
background(255);
}
}
public void mousePressed() {
if(mode == 0) {
float x = mouseX;
float y = mouseY;
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
pointclicked = p;
pointclickedbool = true;
}
}
}
}
if(mode == 4) {
float x = mouseX;
float y = mouseY;
colorFaceHalfEdge = list.getHalfEdgeBySinglePoint(x,y,10);
}
}
void mouseReleased() {
float x = mouseX;
float y = mouseY;
switch (mode){
case 0:
insertMode(x,y);
break;
case 1:
removePointMode(x,y);
break;
case 2:
removeEdgeMode(x,y);
break;
case 4:
colorFace(x, y);
break;
}
}
public void colorFace(float x, float y) {
if(colorFaceHalfEdge != null) {
HalfEdge h = CompGeo.findCWR(colorFaceHalfEdge);
h.printFace();
boolean b = CompGeo.inside(h, new Point(x,y), list.getFar());
if(b) {
h = h.gettwin();
//h = colorFaceHalfEdge;
} else {
//h = h.gettwin();
//h = colorFaceHalfEdge.gettwin();
}
if(h != null) {
Face f = new Face(h, list);
switch (colorFaceColor) {
case 0:
f.daColoring(255,255,255,list, width, height);
break;
case 1:
f.daColoring(0,0,0,list, width, height);
break;
case 2:
f.daColoring(244, 67, 54,list, width, height);
break;
case 3:
f.daColoring(76, 175, 80,list, width, height);
break;
case 4:
f.daColoring(33, 150, 243,list,width,height);
break;
case 5:
f.daColoring(156, 39, 176,list,width,height);
break;
case 6:
f.daColoring(255, 235, 59,list,width,height);
break;
case 7:
f.daColoring(103, 58, 183,list,width,height);
break;
case 8:
f.daColoring(233, 30, 99,list,width,height);
break;
case 9:
f.daColoring(63, 81, 181,list,width,height);
break;
}
}
}
noFill();
}
/*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();
switch (colorFaceColor) {
case 0:
f.daColoring(255,255,255,list, width, height);
break;
case 1:
f.daColoring(0,0,0,list, width, height);
break;
case 2:
f.daColoring(244, 67, 54,list, width, height);
break;
case 3:
f.daColoring(76, 175, 80,list, width, height);
break;
case 4:
f.daColoring(33, 150, 243,list,width,height);
break;
case 5:
f.daColoring(156, 39, 176,list,width,height);
break;
case 6:
f.daColoring(255, 235, 59,list,width,height);
break;
case 7:
f.daColoring(103, 58, 183,list,width,height);
break;
case 8:
f.daColoring(233, 30, 99,list,width,height);
break;
case 9:
f.daColoring(63, 81, 181,list,width,height);
break;
}
}
}
}
}
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) {
pointclickedbool = false;
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
linedrawn = true;
if(p.getY() - 10 < pointclicked.getY() && p.getY() + 10 > pointclicked.getY()
&& p.getX() - 10 < pointclicked.getX() && p.getX() + 10 > pointclicked.getX()) { }
else {
if (!list.intersectsSomething(p, pointclicked)) {
HalfEdge h = new HalfEdge(p, pointclicked);
}
}
}
}
}
} /*else {
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
pointclickedbool = true;
pointclicked = p;
}
}
}
}*/
if(!pointclickedbool && !linedrawn) {
Point p = new Point(x,y);
list.addPoint(p);
}
linedrawn = false;
}
public void removePointMode(float x, float y) {
boolean removePoint = false;
Point removeThis = null;
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
removeThis = p;
removePoint = true;
}
}
}
if(removePoint) {
list.removePoint(removeThis);
//background(255);
}
}
public void removeEdgeMode(float x, float y) {
HalfEdge h = list.getHalfEdgeBySinglePoint(x,y,10);
if(h != null) {
h.Remove();
}
}
/*public void removeEdgeMode(float x, float y) {
if(removeEdge) {
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(removeEdgePoint, p);
if(h != null) {
h.Remove();
//background(255);
}
removeEdge = 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)) {
removeEdgePoint = p;
removeEdge = true;
}
}
}
}
}*/
You can’t perform that action at this time.