1 package edu.berkeley.qfat;
4 import java.awt.event.*;
6 import javax.media.opengl.*;
7 import javax.media.opengl.glu.*;
8 import edu.berkeley.qfat.geom.*;
9 import edu.berkeley.qfat.geom.HasBindingGroup;
10 import edu.wlu.cs.levy.CG.KDTree;
11 import edu.berkeley.qfat.geom.Point;
12 import com.infomatiq.jsi.IntProcedure;
14 public class Mesh implements Iterable<Mesh.T> {
16 public static final float EPSILON = (float)0.0001;
17 public static final Random random = new Random();
19 private RTree<T> triangles = new RTree<T>();
20 private PointSet<Vertex> vertices = new PointSet<Vertex>();
22 public boolean option_wireframe = false;
23 public boolean option_errorNormals = false;
24 public boolean option_selectable = true;
26 public void render(GL gl, Matrix m) {
27 if (option_wireframe) {
28 gl.glDisable(GL.GL_LIGHTING);
29 gl.glBegin(GL.GL_LINES);
30 gl.glColor3f(1, 1, 1);
32 m.times(t.e1().p1.goodp).glVertex(gl);
33 m.times(t.e1().p2.goodp).glVertex(gl);
34 m.times(t.e2().p1.goodp).glVertex(gl);
35 m.times(t.e2().p2.goodp).glVertex(gl);
36 m.times(t.e3().p1.goodp).glVertex(gl);
37 m.times(t.e3().p2.goodp).glVertex(gl);
40 gl.glEnable(GL.GL_LIGHTING);
44 gl.glColor4f((float)(0.25+(0.05*t.color)),
45 (float)(0.25+(0.05*t.color)),
46 (float)(0.75+(0.05*t.color)),
50 if (option_errorNormals)
52 for(Mesh.Vertex p : new Mesh.Vertex[] { t.v1(), t.v2(), t.v3() }) {
54 gl.glBegin(GL.GL_LINES);
55 gl.glColor3f(1, 1, 1);
57 p.p.plus(p.norm().times((float)p.error()*10)).glVertex(gl);
63 public boolean immutableVertices;
64 public Mesh error_against = null;
65 public double error = 0;
67 public Mesh(boolean immutableVertices) { this.immutableVertices = immutableVertices; }
69 public void makeVerticesImmutable() { this.immutableVertices = true; }
70 public float error() { return (float)error; }
72 public int size() { return vertices.size(); }
73 public Iterable<Vertex> vertices() { return vertices; }
74 public Iterator<T> iterator() { return triangles.iterator(); }
76 public void rebindPoints() {
78 for(Mesh.T t : this) {
83 // ask edges to re-implement their bindings
84 for(Mesh.T t : this) {
89 System.out.println("rebound!");
92 public void transform(Matrix m) {
93 ArrayList<Vertex> set = new ArrayList<Vertex>();
94 for(Vertex v : vertices) set.add(v);
95 for(Vertex v : set) v.transform(m.times(v.p), true, null);
96 for(Vertex v : set) v.goodp = v.p;
99 public void rebuild() { /*vertices.rebuild();*/ }
100 public Vec diagonal() { return vertices.diagonal(); }
101 public Point centroid() { return vertices.centroid(); }
102 public Vertex nearest(Point p) { return vertices.nearest(p); }
104 /** compute the volume of the mesh */
105 public float volume() {
108 double area = t.area();
109 Vec origin_to_centroid = new Vec(new Point(0, 0, 0), t.centroid());
110 boolean facingAway = t.norm().dot(origin_to_centroid) > 0;
111 double height = Math.abs(t.norm().dot(origin_to_centroid));
112 total += ((facingAway ? 1 : -1) * area * height) / 3.0;
118 // Vertexices //////////////////////////////////////////////////////////////////////////////
120 /** a vertex in the mesh */
121 public final class Vertex extends HasQuadric implements Visitor {
122 public Point p, goodp;
124 E e; // some edge *leaving* this point
126 private boolean illegal = false;
128 public boolean visible = false;
130 public Point getPoint() { return p; }
131 public float error() { return olderror; }
133 private Vertex(Point p) {
137 if (vertices.get(p) != null) throw new Error();
141 public void reinsert() {
142 vertices.remove(this);
144 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) e.t.reinsert();
147 public float olderror = 0;
148 public void setError(float nerror) {
155 public Vertex hack(GL gl, Point mouse) {
156 double dist = Double.MAX_VALUE;
158 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
159 Vertex v = e.getOther(this);
160 double dist2 = v.getPoint().glProject(gl).distance(mouse);
161 if ((cur==null || dist2 < dist) && v.visible) {
170 public float averageTriangleArea() {
173 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
179 public float averageEdgeLength() {
182 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
189 public Matrix _recomputeFundamentalQuadric() {
190 Matrix m = Matrix.ZERO;
192 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
193 m = m.plus(e.t.norm().fundamentalQuadric(e.t.centroid()));
197 m = m.plus(norm().fundamentalQuadric(this.p).times(count));
200 return m.times(1/(float)count);
203 public HasQuadric nearest() { return error_against==null ? null : error_against.vertices.nearest(p, this); }
204 public void computeError() {
205 if (error_against==null) return;
207 nearest_in_other_mesh != null
208 ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p)
209 : nearest().fundamentalQuadric().preAndPostMultiply(p);
210 if (quadric_count != 0)
211 nerror = (nerror + quadric.preAndPostMultiply(p))/(quadric_count+1);
213 if (!immutableVertices && quadric_count == 0) {
214 //nerror = Math.max(nerror, 0.4f);
217 //System.out.println(nerror);
218 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
219 double ang = e.dihedralAngle();
220 if (ang > Math.PI) throw new Error();
221 if (ang < -Math.PI) throw new Error();
222 float minangle = (float)(Math.PI * 0.8);
223 //nerror += ((ang / Math.PI)*(ang/Math.PI)) * e.length() * 0.05;
225 nerror += (1-e.t.quality())*0.0001;
226 if (ang > minangle) nerror += (ang - minangle);
228 //System.out.println(((ang / Math.PI)*(ang/Math.PI)) * 0.000001);
230 if (e.t.aspect() < 0.2) {
231 nerror += (0.2-e.t.aspect()) * 10;
235 if (!immutableVertices) {
236 Vertex n = (Vertex)nearest();
237 float d = norm().dot(n.norm());
238 if (d > 1 || d < -1) throw new Error();
240 nerror *= (2.0f - d);
242 nerror += 0.0003 * (2.0f + d);
243 nerror *= (2.0f + d);
250 public boolean move(Vec vv, boolean ignoreProblems) {
255 // t2' = t2.getMatrix(t1) * t1'
256 // t2' = t2.getMatrix(t1) * M * t1
257 // t1 = t1.getMatrix(t2) * t2
258 // M * t1 = M * t1.getMatrix(t2) * t2
260 if (bindingGroup!=null && this != bindingGroup.getMaster()) {
261 Matrix m2 = getBindingMatrix(bindingGroup.getMaster());
262 Vec v2 = m2.times(vv.plus(getPoint())).minus(m2.times(getPoint()));
263 return ((Vertex)bindingGroup.getMaster()).move(v2, ignoreProblems);
267 Point pp = vv.plus(getPoint());
268 if (bindingGroup != null) {
270 for(int i=0; i<20 ; i++) {
271 Point p2 = getConstraint().times(pp);
272 pp = pp.midpoint(p2);
273 //System.out.println(m.minus(m2));
276 pp = getConstraint().times(pp);
278 pp = pp.minus(op).norm().times(vv.mag()).plus(op);
281 for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
282 Point pt2 = v.getBindingMatrix(this).times(pt);
284 if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) > 5)
285 throw new Error(v.p+" "+pt2+"\n"+op+" "+pt+"\n"+v.getBindingMatrix(this));
286 if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) < 1/5) throw new Error();
288 good &= v.transform(pt2, ignoreProblems, v.getBindingMatrix(this));
291 if (!good && !ignoreProblems) {
292 for(Vertex v : (Iterable<Vertex>)getBoundPeers())
293 v.transform(v.oldp, true, null);
296 for(Vertex v : (Iterable<Vertex>)getBoundPeers())
297 v.recomputeFundamentalQuadricIfNeighborChanged();
298 for(Vertex v : (Iterable<Vertex>)getBoundPeers())
299 v.reComputeErrorAround();
303 public boolean ok = true;
305 /** does NOT update bound pairs! */
306 private boolean transform(Point newp, boolean ignoreProblems, Matrix yes) {
308 if (immutableVertices) throw new Error();
310 unApplyQuadricToNeighbor();
312 boolean illegalbefore = illegal;
315 if (this.p.minus(newp).mag() > 0.1 && !ignoreProblems) {
317 throw new Exception(""+this.p.minus(newp).mag()+" "+ignoreProblems+" "+yes);
318 } catch(Exception e) {
327 applyQuadricToNeighbor();
329 if (!ignoreProblems) {
332 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
333 e.p2.quadricStale = true;
334 return !illegal || (illegalbefore && illegal);
337 public void checkLegality() {
339 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
340 if (Math.abs(e.dihedralAngle()) > (Math.PI * 0.9) ||
341 Math.abs(e.next.dihedralAngle()) > (Math.PI * 0.9)) illegal = true;
342 if (e.t.aspect() < 0.2) illegal = true;
345 if (!illegal) triangles.range(oldp, this.p, (Visitor<T>)this);
348 public void reComputeErrorAround() {
350 if (nearest_in_other_mesh != null)
351 nearest_in_other_mesh.reComputeError();
352 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
353 e.p2.reComputeError();
356 public boolean visit(Object o) {
357 if (o instanceof Vertex)
358 return ((Vertex)o).e != null && ((Vertex)o).norm().dot(Vertex.this.norm()) >= 0;
360 if (illegal) return false;
361 for(E e = Vertex.this.e; e!=null; e=e.pair.next==Vertex.this.e?null:e.pair.next) {
362 if (!t.has(e.p1) && !t.has(e.p2) && e.intersects(t)) { illegal = true; }
364 if (!e.t.has(t.e1().p1) && !e.t.has(t.e1().p2) && t.e1().intersects(e.t)) { illegal = true; }
365 if (!e.t.has(t.e2().p1) && !e.t.has(t.e2().p2) && t.e2().intersects(e.t)) { illegal = true; }
366 if (!e.t.has(t.e3().p1) && !e.t.has(t.e3().p2) && t.e3().intersects(e.t)) { illegal = true; }
372 public E getEdge() { return e; }
373 public E getFreeIncident() {
374 E ret = getFreeIncident(e, e);
375 if (ret != null) return ret;
376 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
377 System.out.println(e + " " + e.t);
378 throw new Error("unable to find free incident to " + this);
381 public E getFreeIncident(E start, E before) {
382 for(E e = start; e!=null; e=e.pair.next==before?null:e.pair.next)
383 if (e.pair.p2 == this && e.pair.t == null && e.pair.next.t == null)
388 public E getE(Point p2) {
389 Vertex v = vertices.get(p2);
390 if (v==null) return null;
393 public E getE(Vertex p2) {
394 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
395 if (e.p1 == this && e.p2 == p2) return e;
399 private void glNormal(GL gl) {
401 gl.glNormal3f(norm.x, norm.y, norm.z);
404 Vec norm = new Vec(0, 0, 0);
405 for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
407 norm = norm.plus(e.t.norm().times((float)e.prev.angle()));
411 public void bindTo(Vertex p) { bindTo(Matrix.ONE, p); }
415 /** [UNIQUE] an edge */
416 public final class E extends HasBindingGroup implements Comparable<E> {
418 public final Vertex p1, p2;
419 T t; // triangle to our "left"
420 E prev; // previous half-edge
421 E next; // next half-edge
422 E pair; // partner half-edge
423 boolean shattered = false;
425 public boolean intersects(T t) { return t.intersects(p1.p, p2.p); }
427 public Segment getSegment() { return new Segment(p1.getPoint(), p2.getPoint()); }
429 public void bindingGroupChanged(edu.berkeley.qfat.geom.BindingGroup newBindingGroup_) {
431 edu.berkeley.qfat.geom.BindingGroup<E> newBindingGroup =
432 (edu.berkeley.qfat.geom.BindingGroup<E>)newBindingGroup_;
433 if (newBindingGroup==null) return;
434 if (this==newBindingGroup.getMaster()) return;
435 HashSet<E> nbg = new HashSet<E>();
436 for(E eother : (Iterable<E>)newBindingGroup) nbg.add(eother);
437 for(E eother : nbg) {
438 if (next==null || prev==null) continue;
439 if (eother.next==null || eother.prev==null) continue;
441 if (next.isBoundTo(eother.pair.prev.pair) && !prev.isBoundTo(eother.pair.next.pair))
442 prev.bindTo(next.getBindingMatrix(eother.pair.prev.pair), eother.pair.next.pair);
443 if (!next.isBoundTo(eother.pair.prev.pair) && prev.isBoundTo(eother.pair.next.pair))
444 next.bindTo(prev.getBindingMatrix(eother.pair.next.pair), eother.pair.prev.pair);
447 if (next.isBoundTo(eother.prev) && !prev.isBoundTo(eother.next))
448 prev.bindTo(next.getBindingMatrix(eother.prev), eother.next);
449 if (!next.isBoundTo(eother.prev) && prev.isBoundTo(eother.next))
450 next.bindTo(prev.getBindingMatrix(eother.next), eother.prev);
452 if (next.isBoundTo(eother.next) && !prev.isBoundTo(eother.prev))
453 prev.bindTo(next.getBindingMatrix(eother.next), eother.prev);
454 if (!next.isBoundTo(eother.next) && prev.isBoundTo(eother.prev))
455 next.bindTo(prev.getBindingMatrix(eother.prev), eother.next);
460 public float stretchRatio() {
461 Vertex nearest = error_against.nearest(midpoint());
462 float nearest_distance = midpoint().distance(nearest.p);
463 float other_distance =
464 (p1.p.distance(error_against.nearest(p1.p).p)+
465 p2.p.distance(error_against.nearest(p2.p).p))/2;
466 return nearest_distance/other_distance;
468 public float comparator() {
471 public int compareTo(E e) {
472 return e.comparator() > comparator() ? 1 : -1;
474 public void bindEdge(E e, Matrix m) {
476 pair._bindEdge(e.pair, m);
478 public void _bindEdge(E e, Matrix m) {
481 //assumes edges are identical length at binding time
482 Vec reflectionPlaneNormal = e.p2.p.minus(e.p1.p).norm();
483 float a = reflectionPlaneNormal.x;
484 float b = reflectionPlaneNormal.y;
485 float c = reflectionPlaneNormal.z;
486 Matrix reflectionMatrix =
487 new Matrix( 1-2*a*a, -2*a*b, -2*a*c, 0,
488 -2*a*b, 1-2*b*b, -2*b*c, 0,
489 -2*a*c, -2*b*c, 1-2*c*c, 0,
491 m = m.times(Matrix.translate(e.midpoint().minus(Point.ORIGIN))
492 .times(reflectionMatrix)
493 .times(Matrix.translate(Point.ORIGIN.minus(e.midpoint()))));
494 System.out.println(reflectionPlaneNormal);
495 System.out.println(" " + p1.p + " " + m.times(e.p1.p));
496 System.out.println(" " + p2.p + " " + m.times(e.p2.p));
499 if (m.times(e.p1.p).minus(p1.p).mag() > EPSILON) throw new Error();
500 if (m.times(e.p2.p).minus(p2.p).mag() > EPSILON) throw new Error();
505 public void dobind() {
506 for(E e : (Iterable<E>)getBoundPeers()) {
507 if (e==this) continue;
508 p1.bindTo(getBindingMatrix(e), e.p1);
509 p2.bindTo(getBindingMatrix(e), e.p2);
510 e.p1.setConstraint(getConstraint());
511 e.p2.setConstraint(getConstraint());
515 public Point shatter() {
516 if (shattered || destroyed) return null;
522 for(E e : (Iterable<E>)getBoundPeers()) {
525 E pnext = e.pair.next;
526 E pprev = e.pair.prev;
527 Point mid = e.midpoint();
528 Vertex r = e.next.p2;
529 Vertex l = e.pair.next.p2;
533 newT(r.p, e.p1.p, mid, null, 0);
534 newT(r.p, mid, e.p2.p, null, 0);
535 newT(l.p, mid, e.p1.p, null, 0);
536 newT(l.p, e.p2.p, mid, null, 0);
539 for(E e : (Iterable<E>)getBoundPeers()) {
540 Point mid = e.midpoint();
542 first = e.p1.getE(mid);
545 firstq = e.p2.getE(mid).pair;
548 e.p1.getE(mid). bindTo(e.getBindingMatrix(firste), first);
549 e.p1.getE(mid).pair. bindTo(e.getBindingMatrix(firste), first.pair);
550 e.p2.getE(mid).pair. bindTo(e.getBindingMatrix(firste), firstq);
551 e.p2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
554 first.setConstraint(firste.getConstraint());
555 firstq.setConstraint(firste.getConstraint());
560 public boolean destroyed = false;
561 public void destroy() {
562 if (destroyed) return;
564 pair.destroyed = true;
566 if (t != null) t.destroy();
569 if (pair.t != null) pair.t.destroy();
572 if (next.t != null) next.t.destroy();
573 if (prev.t != null) prev.t.destroy();
577 if (pair.next.t != null) pair.next.t.destroy();
578 if (pair.prev.t != null) pair.next.t.destroy();
582 pair.prev.next = next;
583 next.prev = pair.prev;
584 prev.next = pair.next;
586 if (p1.e == this) p1.e = prev.next;
587 if (pair.p1.e == pair) pair.p1.e = pair.prev.next;
590 private void sync() {
591 this.prev.next = this;
592 this.next.prev = this;
593 this.pair.pair = this;
594 if (this.next.p1 != p2) throw new Error();
595 if (this.prev.p2 != p1) throw new Error();
596 if (this.p1.e == null) this.p1.e = this;
597 if (!added) added = true;
599 private boolean added = false;
601 public T makeT(int colorclass) { return t==null ? (t = new T(this, colorclass)) : t; }
603 public double dihedralAngle() {
604 Vec v1 = t.norm().times(-1);
605 Vec v2 = pair.t.norm().times(-1);
606 double prod = v1.norm().dot(v2.norm());
607 prod = Math.min(1,prod);
608 prod = Math.max(-1,prod);
609 double ret = Math.acos(prod);
610 if (Double.isNaN(ret)) throw new Error("nan! " + prod);
614 /** angle between this half-edge and the next */
615 public double angle() {
616 Vec v1 = next.p2.p.minus(p2.p);
617 Vec v2 = this.p1.p.minus(p2.p);
618 return Math.acos(v1.norm().dot(v2.norm()));
621 public Vertex getOther(Vertex v) {
622 if (this.p1 == v) return p2;
623 if (this.p2 == v) return p1;
627 public void makeAdjacent(E e) {
628 if (this.next == e) return;
629 if (p2 != e.p1) throw new Error("cannot make adjacent -- no shared vertex");
630 if (t != null || e.t != null) throw new Error("cannot make adjacent -- edges not both free ");
632 E freeIncident = p2.getFreeIncident(e, this);
634 e.prev.next = freeIncident.next;
635 freeIncident.next.prev = e.prev;
637 freeIncident.next = this.next;
638 this.next.prev = freeIncident;
647 /** creates an isolated edge out in the middle of space */
648 public E(Point p1, Point p2) {
649 if (vertices.get(p1) != null) throw new Error();
650 if (vertices.get(p2) != null) throw new Error();
651 this.p1 = new Vertex(p1);
652 this.p2 = new Vertex(p2);
653 this.prev = this.next = this.pair = new E(this, this, this);
655 this.p2.e = this.pair;
659 /** adds a new half-edge from prev.p2 to p2 */
660 public E(E prev, Point p) {
662 p2 = vertices.get(p);
663 if (p2 == null) p2 = new Vertex(p);
667 if (p2.getE(p1) != null) throw new Error();
669 this.next = this.pair = new E(this, this, prev.next);
671 E q = p2.getFreeIncident();
673 this.next.prev = this;
675 this.prev.next = this;
676 this.pair = new E(q, this, z);
678 if (p2.e==null) p2.e = this.pair;
682 /** adds a new half-edge to the mesh with a given predecessor, successor, and pair */
683 public E(E prev, E pair, E next) {
691 public Point midpoint() { return new Point((p1.p.x+p2.p.x)/2, (p1.p.y+p2.p.y)/2, (p1.p.z+p2.p.z)/2); }
692 public boolean has(Vertex v) { return v==p1 || v==p2; }
693 public float length() { return p1.p.minus(p2.p).mag(); }
694 public String toString() { return p1+"->"+p2; }
698 public E makeE(Point p1, Point p2) {
699 Vertex v1 = vertices.get(p1);
700 Vertex v2 = vertices.get(p2);
701 if (v1 != null && v2 != null) {
703 if (e != null) return e;
705 if (e != null) return e;
707 if (v1 != null) return new E(v1.getFreeIncident(), p2);
708 if (v2 != null) return new E(v2.getFreeIncident(), p1).pair;
709 return new E(p1, p2);
711 public boolean coalesce = false;
712 private static float round(float f) {
713 return Math.round(f*1000)/1000f;
715 public T newT(Point p1, Point p2, Point p3, Vec norm, int colorclass) {
718 for(Vertex v : vertices) { if (p1.distance(v.p) < EPSILON) { p1 = v.p; break; } }
719 for(Vertex v : vertices) { if (p2.distance(v.p) < EPSILON) { p2 = v.p; break; } }
720 for(Vertex v : vertices) { if (p3.distance(v.p) < EPSILON) { p3 = v.p; break; } }
722 p1 = new Point(round(p1.x), round(p1.y), round(p1.z));
723 p2 = new Point(round(p2.x), round(p2.y), round(p2.z));
724 p3 = new Point(round(p3.x), round(p3.y), round(p3.z));
728 Vec norm2 = p3.minus(p1).cross(p2.minus(p1));
729 float dot = norm.dot(norm2);
730 //if (Math.abs(dot) < EPointSILON) throw new Error("dot products within evertsilon of each other: "+norm+" "+norm2);
731 if (dot < 0) { Point p = p1; p1=p2; p2 = p; }
733 E e12 = makeE(p1, p2);
734 E e23 = makeE(p2, p3);
735 E e31 = makeE(p3, p1);
736 while(e12.next != e23 || e23.next != e31 || e31.next != e12) {
737 e12.makeAdjacent(e23);
738 e23.makeAdjacent(e31);
739 e31.makeAdjacent(e12);
741 T ret = e12.makeT(colorclass);
742 if (e12.t == null) throw new Error();
743 if (e23.t == null) throw new Error();
744 if (e31.t == null) throw new Error();
748 private int max_serial = 0;
749 /** [UNIQUE] a triangle (face) */
750 public final class T extends Triangle {
752 public final int color;
753 public final int colorclass;
755 public final int serial = max_serial++;
756 public boolean occluded;
758 T(E e1, int colorclass) {
762 if (e1==e2 || e1==e3) throw new Error();
763 if (e3.next!=e1) throw new Error();
764 if (e1.t!=null || e2.t!=null || e3.t!=null) throw new Error("non-manifold surface or disagreeing normals");
767 e1.next.next.t = this;
769 // FIXME: check for sealed/watertight surface once construction is complete (and infer normal(s)?)
771 int color = Math.abs(random.nextInt());
774 if (e1().pair.t != null && color == e1().pair.t.color) { color++; continue; }
775 if (e2().pair.t != null && color == e2().pair.t.color) { color++; continue; }
776 if (e3().pair.t != null && color == e3().pair.t.color) { color++; continue; }
780 this.colorclass = colorclass;
783 public E e1() { return e1; }
784 public E e2() { return e1.next; }
785 public E e3() { return e1.prev; }
786 public Vertex v1() { return e1.p1; }
787 public Vertex v2() { return e1.p2; }
788 public Vertex v3() { return e1.next.p2; }
789 public Point p1() { return e1.p1.p; }
790 public Point p2() { return e1.p2.p; }
791 public Point p3() { return e1.next.p2.p; }
792 public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; }
793 public boolean has(Vertex v) { return v1()==v || v2()==v || v3()==v; }
795 public void removeFromRTree() { triangles.remove(this); }
796 public void addToRTree() { triangles.insert(this); }
797 public void destroy() { triangles.remove(this); }
798 public void reinsert() { triangles.remove(this); triangles.add(this); }
800 public boolean shouldBeDrawn() {
802 if (e1().bindingGroupSize() <= 1) return false;
803 if (e2().bindingGroupSize() <= 1) return false;
804 if (e3().bindingGroupSize() <= 1) return false;
809 public void glTriangle(GL gl, Matrix m) {
810 gl.glPushName(serial);
811 gl.glBegin(GL.GL_TRIANGLES);
817 /** issue gl.glVertex() for each of the triangle's points */
818 public void glVertices(GL gl, Matrix m) {
819 if (!shouldBeDrawn()) return;
820 super.glVertices(gl, m);