X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=d56e2a0d639a827160e9adbd35611e0d7515c21e;hp=7f806f8615c51fcfc0f152bb722732675a9ed98f;hb=2a2e64829786ee415fd0c0f16957c55e174b793b;hpb=fe5601878bcdd906f4b58aa204af45272bf21c61 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 7f806f8..d56e2a0 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -19,6 +19,47 @@ public class Mesh implements Iterable { private RTree triangles = new RTree(); private PointSet vertices = new PointSet(); + + public boolean option_wireframe = false; + public boolean option_errorNormals = false; + + public void render(GL gl, Matrix m) { + if (option_wireframe) { + gl.glDisable(GL.GL_LIGHTING); + gl.glBegin(GL.GL_LINES); + gl.glColor3f(1, 1, 1); + for (T t : this) { + m.times(t.e1().p1.goodp).glVertex(gl); + m.times(t.e1().p2.goodp).glVertex(gl); + m.times(t.e2().p1.goodp).glVertex(gl); + m.times(t.e2().p2.goodp).glVertex(gl); + m.times(t.e3().p1.goodp).glVertex(gl); + m.times(t.e3().p2.goodp).glVertex(gl); + } + gl.glEnd(); + gl.glEnable(GL.GL_LIGHTING); + return; + } + for(T t : this) { + gl.glColor4f((float)(0.25+(0.05*t.color)), + (float)(0.25+(0.05*t.color)), + (float)(0.75+(0.05*t.color)), + (float)0.3); + t.glTriangle(gl, m); + } + if (option_errorNormals) + for(T t : this) + for(Mesh.Vertex p : new Mesh.Vertex[] { t.v1(), t.v2(), t.v3() }) { + if (p.ok) { + gl.glBegin(GL.GL_LINES); + gl.glColor3f(1, 1, 1); + p.p.glVertex(gl); + p.p.plus(p.norm().times((float)p.error()*10)).glVertex(gl); + gl.glEnd(); + } + } + } + public boolean immutableVertices; public Mesh error_against = null; public double error = 0; @@ -110,6 +151,22 @@ public class Mesh implements Iterable { error += olderror; } + /* + public Vertex hack(GL gl, Point mouse) { + double dist = Double.MAX_VALUE; + Vertex cur = null; + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { + Vertex v = e.getOther(this); + double dist2 = v.getPoint().glProject(gl).distance(mouse); + if ((cur==null || dist2 < dist) && v.visible) { + dist = dist2; + cur = v; + } + } + return cur; + } + */ + public float averageTriangleArea() { int count = 0; float ret = 0; @@ -308,6 +365,7 @@ public class Mesh implements Iterable { return !illegal; } + public E getEdge() { return e; } public E getFreeIncident() { E ret = getFreeIncident(e, e); if (ret != null) return ret; @@ -362,6 +420,8 @@ public class Mesh implements Iterable { public boolean intersects(T t) { return t.intersects(p1.p, p2.p); } + public Segment getSegment() { return new Segment(p1.getPoint(), p2.getPoint()); } + public void bindingGroupChanged(edu.berkeley.qfat.geom.BindingGroup newBindingGroup_) { edu.berkeley.qfat.geom.BindingGroup newBindingGroup = @@ -554,6 +614,12 @@ public class Mesh implements Iterable { return Math.acos(v1.norm().dot(v2.norm())); } + public Vertex getOther(Vertex v) { + if (this.p1 == v) return p2; + if (this.p2 == v) return p1; + throw new Error(); + } + public void makeAdjacent(E e) { if (this.next == e) return; if (p2 != e.p1) throw new Error("cannot make adjacent -- no shared vertex");