774c7f97f577d9a9442e796dfb114a32bc161f20
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
1 package edu.berkeley.qfat;
2 import java.awt.*;
3 import java.util.*;
4 import java.awt.event.*;
5 import javax.swing.*;
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;
13
14 public class Mesh implements Iterable<Mesh.T> {
15
16     public static final float EPSILON = (float)0.0001;
17     public static final Random random = new Random();
18
19     private RTree<T>         triangles = new RTree<T>();
20     private PointSet<Vertex> vertices  = new PointSet<Vertex>();
21
22     public boolean immutableVertices;
23     public Mesh    error_against      = null;
24     public double  error              = 0;
25
26     public Mesh(boolean immutableVertices) { this.immutableVertices = immutableVertices; }
27
28     public void makeVerticesImmutable() { this.immutableVertices = true; }
29     public float error() { return (float)error; }
30
31     public int size() { return vertices.size(); }
32     public Iterable<Vertex> vertices() { return vertices; }
33     public Iterator<T> iterator() { return triangles.iterator(); }
34
35     public void rebindPoints() {
36         // unbind all points
37         for(Mesh.T t : this) {
38             t.v1().unbind();
39             t.v2().unbind();
40             t.v3().unbind();
41         }
42         // ask edges to re-implement their bindings
43         for(Mesh.T t : this) {
44             t.e1().dobind();
45             t.e2().dobind();
46             t.e3().dobind();
47         }
48         System.out.println("rebound!");
49     }
50
51     public void transform(Matrix m) {
52         ArrayList<Vertex> set = new ArrayList<Vertex>();
53         for(Vertex v : vertices) set.add(v);
54         for(Vertex v : set) v.transform(m.times(v.p), true, null);
55     }
56
57     public void rebuild() { /*vertices.rebuild();*/ }
58     public Vec diagonal() { return vertices.diagonal(); }
59     public Point centroid() { return vertices.centroid(); }
60     public Vertex nearest(Point p) { return vertices.nearest(p); }
61
62     /** compute the volume of the mesh */
63     public float volume() {
64         double total = 0;
65         for(T t : this) {
66             double area = t.area();
67             Vec origin_to_centroid = new Vec(new Point(0, 0, 0), t.centroid());
68             boolean facingAway = t.norm().dot(origin_to_centroid) > 0;
69             double height = Math.abs(t.norm().dot(origin_to_centroid));
70             total += ((facingAway ? 1 : -1) * area * height) / 3.0;
71         }
72         return (float)total;
73     }
74
75
76     // Vertexices //////////////////////////////////////////////////////////////////////////////
77
78     /** a vertex in the mesh */
79     public final class Vertex extends HasQuadric implements Visitor {
80         public Point p, goodp;
81         public Point oldp;
82         E e;                // some edge *leaving* this point
83
84         private boolean illegal = false;
85
86         public Point getPoint() { return p; }
87         public float error() { return olderror; }
88
89         private Vertex(Point p) {
90             this.p = p;
91             this.goodp = p;
92             if (vertices.get(p) != null) throw new Error();
93             vertices.add(this);
94         }
95
96         public void reinsert() {
97             vertices.remove(this);
98             vertices.add(this);
99             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) e.t.reinsert();
100         }
101
102         public float olderror = 0;
103         public void setError(float nerror) {
104             error -= olderror;
105             olderror = nerror;
106             error += olderror;
107         }
108
109         public float averageTriangleArea() {
110             int count = 0;
111             float ret = 0;
112             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
113                 ret += e.t.area();
114                 count++;
115             }
116             return ret/count;
117         }
118         public float averageEdgeLength() {
119             int count = 0;
120             float ret = 0;
121             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
122                 ret += e.length();
123                 count++;
124             }
125             return ret/count;
126         }
127
128         public Matrix _recomputeFundamentalQuadric() {
129             Matrix m = Matrix.ZERO;
130             int count = 0;
131             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
132                 m = m.plus(e.t.norm().fundamentalQuadric(e.t.centroid()));
133                 count++;
134             }
135             return m.times(1/(float)count);
136         }
137
138         public HasQuadric nearest() { return error_against==null ? null : error_against.vertices.nearest(p, this); }
139         public void computeError() {
140             if (error_against==null) return;
141             float nerror =
142                 nearest_in_other_mesh != null
143                 ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p)
144                 : nearest().fundamentalQuadric().preAndPostMultiply(p);
145             if (quadric_count != 0)
146                 nerror = (nerror + quadric.preAndPostMultiply(p))/(quadric_count+1);
147
148             if (!immutableVertices && quadric_count == 0)
149                 nerror *= 2;
150                 
151             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
152                 double ang = Math.abs(e.dihedralAngle());
153                 if (ang > Math.PI) throw new Error();
154                 float minangle = (float)(Math.PI * 0.8);
155                 if (ang > minangle) nerror += (ang - minangle);
156                 if (e.t.aspect() < 0.2) {
157                     nerror += (0.2-e.t.aspect()) * 10;
158                 }
159             }
160
161             setError(nerror);
162         }
163
164         public boolean move(Matrix m, boolean ignoreProblems) {
165             boolean good = true;
166
167             //     t1' = M * t1
168             //     t2' = t2.getMatrix(t1) * t1'
169             //     t2' = t2.getMatrix(t1) * M * t1
170             //     t1 =     t1.getMatrix(t2) * t2
171             // M * t1 = M * t1.getMatrix(t2) * t2
172             Point op = this.p;
173             Point pt = m.times(this.p);
174             for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
175                 Point pt2 = v.getBindingMatrix(this).times(pt);
176                 /*
177                 if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) > 5)
178                     throw new Error(v.p+" "+pt2+"\n"+op+" "+pt+"\n"+v.getBindingMatrix(this));
179                 if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) < 1/5) throw new Error();
180                 */
181                 good &= v.transform(pt2,
182                                     ignoreProblems, v.getBindingMatrix(this));
183             }
184
185             for(Vertex v : (Iterable<Vertex>)getBoundPeers())
186                 v.recomputeFundamentalQuadricIfNeighborChanged();
187             return good;
188         }
189
190         /** does NOT update bound pairs! */
191         private boolean transform(Point newp, boolean ignoreProblems, Matrix yes) {
192             this.oldp = this.p;
193             if (immutableVertices) throw new Error();
194
195             unApplyQuadricToNeighbor();
196
197
198             illegal = false;
199             if (this.p.minus(newp).mag() > 0.1 && !ignoreProblems) {
200             /*
201                 try {
202                     throw new Exception(""+this.p.minus(newp).mag()+" "+ignoreProblems+" "+yes);
203                 } catch(Exception e) {
204                     e.printStackTrace();
205                 }
206             */
207                 illegal = true;
208             }
209
210             this.p = newp;
211             reinsert();
212             applyQuadricToNeighbor();
213
214             if (!ignoreProblems) {
215                 checkLegality();
216             }
217             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
218                 e.p2.quadricStale = true;
219             return !illegal;
220         } 
221
222         public void checkLegality() {
223             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
224                 if (Math.abs(e.dihedralAngle()) > (Math.PI * 0.9) ||
225                     Math.abs(e.next.dihedralAngle()) > (Math.PI * 0.9)) illegal = true;
226                 if (e.t.aspect() < 0.2) illegal = true;
227             }
228             if (!illegal) triangles.range(oldp, this.p, (Visitor<T>)this);
229         }
230
231         public void reComputeErrorAround() {
232             reComputeError();
233             if (nearest_in_other_mesh != null)
234                 nearest_in_other_mesh.reComputeError();
235             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
236                 e.p2.reComputeError();
237         }
238
239         public boolean visit(Object o) {
240             if (o instanceof Vertex)
241                 return ((Vertex)o).e != null && ((Vertex)o).norm().dot(Vertex.this.norm()) >= 0;
242             T t = (T)o;
243             if (illegal) return false;
244             for(E e = Vertex.this.e; e!=null; e=e.pair.next==Vertex.this.e?null:e.pair.next) {
245                 if (!t.has(e.p1) && !t.has(e.p2) && e.intersects(t)) { illegal = true; }
246                 if (e.t != null) {
247                     if (!e.t.has(t.e1().p1) && !e.t.has(t.e1().p2) && t.e1().intersects(e.t)) { illegal = true; }
248                     if (!e.t.has(t.e2().p1) && !e.t.has(t.e2().p2) && t.e2().intersects(e.t)) { illegal = true; }
249                     if (!e.t.has(t.e3().p1) && !e.t.has(t.e3().p2) && t.e3().intersects(e.t)) { illegal = true; }
250                 }
251             }
252             return !illegal;
253         }
254
255         public E getFreeIncident() {
256             E ret = getFreeIncident(e, e);
257             if (ret != null) return ret;
258             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
259                 System.out.println(e + " " + e.t);
260             throw new Error("unable to find free incident to " + this);
261         }
262
263         public E getFreeIncident(E start, E before) {
264             for(E e = start; e!=null; e=e.pair.next==before?null:e.pair.next)
265                 if (e.pair.p2 == this && e.pair.t == null && e.pair.next.t == null)
266                     return e.pair;
267             return null;
268         }
269
270         public E getE(Point p2) {
271             Vertex v = vertices.get(p2);
272             if (v==null) return null;
273             return getE(v);
274         }
275         public E getE(Vertex p2) {
276             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
277                 if (e.p1 == this && e.p2 == p2) return e;
278             return null;
279         }
280
281         private void glNormal(GL gl) {
282             Vec norm = norm();
283             gl.glNormal3f(norm.x, norm.y, norm.z);
284         }
285         public Vec norm() {
286             Vec norm = new Vec(0, 0, 0);
287             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
288                 if (e.t != null)
289                     norm = norm.plus(e.t.norm().times((float)e.prev.angle()));
290             return norm.norm();
291         }
292
293         public void bindTo(Vertex p) { bindTo(Matrix.ONE, p); }
294     }
295
296
297     /** [UNIQUE] an edge */
298     public final class E extends HasBindingGroup implements Comparable<E> {
299
300         public final Vertex p1, p2;
301         T t;     // triangle to our "left"
302         E prev;  // previous half-edge
303         E next;  // next half-edge
304         E pair;  // partner half-edge
305         boolean shattered = false;
306
307         public boolean intersects(T t) { return t.intersects(p1.p, p2.p); }
308
309         public void bindingGroupChanged(edu.berkeley.qfat.geom.BindingGroup newBindingGroup_) {
310
311             edu.berkeley.qfat.geom.BindingGroup<E> newBindingGroup =
312                 (edu.berkeley.qfat.geom.BindingGroup<E>)newBindingGroup_;
313             if (newBindingGroup==null) return;
314             if (this==newBindingGroup.getMaster()) return;
315             for(E eother : (Iterable<E>)newBindingGroup) {
316                 if (next==null || prev==null) continue;
317                 if (eother.next==null || eother.prev==null) continue;
318                 if (next.isBoundTo(eother.pair.prev.pair) && !prev.isBoundTo(eother.pair.next.pair))
319                     prev.bindTo(next.getBindingMatrix(eother.pair.prev.pair), eother.pair.next.pair);
320                 if (!next.isBoundTo(eother.pair.prev.pair) && prev.isBoundTo(eother.pair.next.pair))
321                     next.bindTo(prev.getBindingMatrix(eother.pair.next.pair), eother.pair.prev.pair);
322             }
323
324         }
325
326         public float stretchRatio() {
327             Vertex nearest = error_against.nearest(midpoint());
328             float nearest_distance = midpoint().distance(nearest.p);
329             float other_distance =
330                 (p1.p.distance(error_against.nearest(p1.p).p)+
331                  p2.p.distance(error_against.nearest(p2.p).p))/2;
332             return nearest_distance/other_distance;
333         }
334         public float comparator() {
335             return length();
336             //return t==null?0:(1/t.aspect());
337         }
338         public int compareTo(E e) {
339             return e.comparator() > comparator() ? 1 : -1;
340         }
341         public void bindEdge(E e, Matrix m) {
342             _bindEdge(e, m);
343             pair._bindEdge(e.pair, m);
344         }
345         public void _bindEdge(E e, Matrix m) {
346             e = e.pair;
347             /*
348             //assumes edges are identical length at binding time
349             Vec reflectionPlaneNormal = e.p2.p.minus(e.p1.p).norm();
350             float a = reflectionPlaneNormal.x;
351             float b = reflectionPlaneNormal.y;
352             float c = reflectionPlaneNormal.z;
353             Matrix reflectionMatrix =
354                 new Matrix( 1-2*a*a,  -2*a*b,  -2*a*c, 0,
355                             -2*a*b,  1-2*b*b,  -2*b*c, 0,
356                             -2*a*c,   -2*b*c, 1-2*c*c, 0,
357                             0,       0,       0,       1);
358             m = m.times(Matrix.translate(e.midpoint().minus(Point.ORIGIN))
359                         .times(reflectionMatrix)
360                         .times(Matrix.translate(Point.ORIGIN.minus(e.midpoint()))));
361             System.out.println(reflectionPlaneNormal);
362             System.out.println("  " + p1.p + " " + m.times(e.p1.p));
363             System.out.println("  " + p2.p + " " + m.times(e.p2.p));
364             */
365             if (m.times(e.p1.p).minus(p1.p).mag() > EPSILON) throw new Error();
366             if (m.times(e.p2.p).minus(p2.p).mag() > EPSILON) throw new Error();
367             this.bindTo(m, e);
368         }
369         
370         public void dobind() {
371             for(E e : (Iterable<E>)getBoundPeers()) {
372                 if (e==this) continue;
373                 p1.bindTo(getBindingMatrix(e), e.p1);
374                 p2.bindTo(getBindingMatrix(e), e.p2);
375             }
376         }
377
378         public Point shatter() {
379             if (shattered || destroyed) return null;
380             shattered = true;
381             E first = null;
382             E firste = null;
383             E firstx = null;
384             E firstq = null;
385             for(E e : (Iterable<E>)getBoundPeers()) {
386                 E enext = e.next;
387                 E eprev = e.prev;
388                 E pnext = e.pair.next;
389                 E pprev = e.pair.prev;
390                 Point mid = e.midpoint();
391                 Vertex r = e.next.p2;
392                 Vertex l = e.pair.next.p2;
393                 e.destroy();
394                 e.pair.destroy();
395                 newT(r.p, e.p1.p, mid,    null, 0);
396                 newT(r.p, mid,    e.p2.p, null, 0);
397                 newT(l.p, mid,    e.p1.p, null, 0);
398                 newT(l.p, e.p2.p, mid,    null, 0);
399             }
400             for(E e : (Iterable<E>)getBoundPeers()) {
401                 Point mid = e.midpoint();
402                 if (first==null) {
403                     first = e.p1.getE(mid);
404                     firste = e;
405                     firstx = e.pair;
406                     firstq = e.p2.getE(mid).pair;
407                     continue;
408                 }
409                 e.p1.getE(mid).          bindTo(e.getBindingMatrix(firste), first);
410                 e.p1.getE(mid).pair.     bindTo(e.getBindingMatrix(firste), first.pair);
411                 e.p2.getE(mid).pair.     bindTo(e.getBindingMatrix(firste), firstq);
412                 e.p2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
413             }
414             return null;
415         }
416
417         public boolean destroyed = false;
418         public void destroy() {
419             if (destroyed) return;
420             destroyed = true;
421             pair.destroyed = true;
422
423             if (t != null) t.destroy();
424             t = null;
425
426             if (pair.t != null) pair.t.destroy();
427             pair.t = null;
428
429             if (next.t != null) next.t.destroy();
430             if (prev.t != null) prev.t.destroy();
431             next.t = null;
432             prev.t = null;
433
434             if (pair.next.t != null) pair.next.t.destroy();
435             if (pair.prev.t != null) pair.next.t.destroy();
436             pair.next.t = null;
437             pair.prev.t = null;
438
439             pair.prev.next = next;
440             next.prev = pair.prev;
441             prev.next = pair.next;
442             pair.next = prev;
443             if (p1.e == this) p1.e = prev.next;
444             if (pair.p1.e == pair) pair.p1.e = pair.prev.next;
445         }
446
447         private void sync() {
448             this.prev.next = this;
449             this.next.prev = this;
450             this.pair.pair = this;
451             if (this.next.p1 != p2) throw new Error();
452             if (this.prev.p2 != p1) throw new Error();
453             if (this.p1.e == null) this.p1.e = this;
454             if (!added) added = true;
455         }
456         private boolean added = false;
457
458         public T makeT(int colorclass) { return t==null ? (t = new T(this, colorclass)) : t; }
459
460         public double dihedralAngle() {
461             Vec v1 = t.norm().times(-1);
462             Vec v2 = pair.t.norm().times(-1);
463             return Math.acos(v1.norm().dot(v2.norm()));
464         }
465
466         /** angle between this half-edge and the next */
467         public double angle() {
468             Vec v1 = next.p2.p.minus(p2.p);
469             Vec v2 = this.p1.p.minus(p2.p);
470             return Math.acos(v1.norm().dot(v2.norm()));
471         }
472
473         public void makeAdjacent(E e) {
474             if (this.next == e) return;
475             if (p2 != e.p1) throw new Error("cannot make adjacent -- no shared vertex");
476             if (t != null || e.t != null) throw new Error("cannot make adjacent -- edges not both free ");
477
478             E freeIncident = p2.getFreeIncident(e, this);
479
480             e.prev.next = freeIncident.next;
481             freeIncident.next.prev = e.prev;
482
483             freeIncident.next = this.next;
484             this.next.prev = freeIncident;
485             
486             this.next = e;
487             e.prev = this;
488
489             sync();
490             freeIncident.sync();
491         }
492
493         /** creates an isolated edge out in the middle of space */
494         public E(Point p1, Point p2) {
495             if (vertices.get(p1) != null) throw new Error();
496             if (vertices.get(p2) != null) throw new Error();
497             this.p1 = new Vertex(p1);
498             this.p2 = new Vertex(p2);
499             this.prev = this.next = this.pair = new E(this, this, this);
500             this.p1.e = this;
501             this.p2.e = this.pair;
502             sync();
503         }
504
505         /** adds a new half-edge from prev.p2 to p2 */
506         public E(E prev, Point p) {
507             Vertex p2;
508             p2 = vertices.get(p);
509             if (p2 == null) p2 = new Vertex(p);
510             this.p1 = prev.p2;
511             this.p2 = p2;
512             this.prev = prev;
513             if (p2.getE(p1) != null) throw new Error();
514             if (p2.e==null) {
515                 this.next = this.pair = new E(this, this, prev.next);
516             } else {
517                 E q = p2.getFreeIncident();
518                 this.next = q.next;
519                 this.next.prev = this;
520                 E z = prev.next;
521                 this.prev.next = this;
522                 this.pair = new E(q, this, z);
523             }
524             if (p2.e==null) p2.e = this.pair;
525             sync();
526         }
527
528         /** adds a new half-edge to the mesh with a given predecessor, successor, and pair */
529         public E(E prev, E pair, E next) {
530             this.p1 = prev.p2;
531             this.p2 = next.p1;
532             this.prev = prev;
533             this.next = next;
534             this.pair = pair;
535             sync();
536         }
537         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); }
538         public boolean has(Vertex v) { return v==p1 || v==p2; }
539         public float length() { return p1.p.minus(p2.p).mag(); }
540         public String toString() { return p1+"->"+p2; }
541
542     }
543
544     public E makeE(Point p1, Point p2) {
545         Vertex v1 = vertices.get(p1);
546         Vertex v2 = vertices.get(p2);
547         if (v1 != null && v2 != null) {
548             E e = v1.getE(v2);
549             if (e != null) return e;
550             e = v2.getE(v1);
551             if (e != null) return e;
552         }
553         if (v1 != null) return new E(v1.getFreeIncident(), p2);
554         if (v2 != null) return new E(v2.getFreeIncident(), p1).pair;
555         return new E(p1, p2);
556     }
557     public T newT(Point p1, Point p2, Point p3, Vec norm, int colorclass) {
558         if (norm != null) {
559             Vec norm2 = p3.minus(p1).cross(p2.minus(p1));
560             float dot = norm.dot(norm2);
561             //if (Math.abs(dot) < EPointSILON) throw new Error("dot products within evertsilon of each other: "+norm+" "+norm2);
562             if (dot < 0) { Point p = p1; p1=p2; p2 = p; }
563         }
564         E e12 = makeE(p1, p2);
565         E e23 = makeE(p2, p3);
566         E e31 = makeE(p3, p1);
567         while(e12.next != e23 || e23.next != e31 || e31.next != e12) {
568             e12.makeAdjacent(e23);
569             e23.makeAdjacent(e31);
570             e31.makeAdjacent(e12);
571         }
572         T ret = e12.makeT(colorclass);
573         if (e12.t == null) throw new Error();
574         if (e23.t == null) throw new Error();
575         if (e31.t == null) throw new Error();
576         return ret;
577     }
578
579     /** [UNIQUE] a triangle (face) */
580     public final class T extends Triangle {
581         public final E e1;
582         public final int color;
583         public final int colorclass;
584
585         T(E e1, int colorclass) {
586             this.e1 = e1;
587             E e2 = e1.next;
588             E e3 = e2.next;
589             if (e1==e2 || e1==e3) throw new Error();
590             if (e3.next!=e1) throw new Error();
591             if (e1.t!=null || e2.t!=null || e3.t!=null) throw new Error("non-manifold surface or disagreeing normals");
592             e1.t = this;
593             e1.next.t = this;
594             e1.next.next.t = this;
595
596             // FIXME: check for sealed/watertight surface once construction is complete (and infer normal(s)?)
597
598             int color = Math.abs(random.nextInt());
599             while(true) {
600                 color = color % 4;
601                 if (e1().pair.t != null && color == e1().pair.t.color) { color++; continue; }
602                 if (e2().pair.t != null && color == e2().pair.t.color) { color++; continue; }
603                 if (e3().pair.t != null && color == e3().pair.t.color) { color++; continue; }
604                 break;
605             }
606             this.color = color;
607             this.colorclass = colorclass;
608             triangles.add(this);
609         }
610         public E e1() { return e1; }
611         public E e2() { return e1.next; }
612         public E e3() { return e1.prev; }
613         public Vertex v1() { return e1.p1; }
614         public Vertex v2() { return e1.p2; }
615         public Vertex v3() { return e1.next.p2; }
616         public Point p1() { return e1.p1.p; }
617         public Point p2() { return e1.p2.p; }
618         public Point p3() { return e1.next.p2.p; }
619         public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; }
620         public boolean has(Vertex v) { return v1()==v || v2()==v || v3()==v; }
621
622         public void removeFromRTree() { triangles.remove(this); }
623         public void addToRTree() { triangles.insert(this); }
624         public void destroy() { triangles.remove(this); }
625         public void reinsert() { triangles.remove(this); triangles.add(this); }
626
627         public boolean shouldBeDrawn() {
628             /*
629             if (e1().bindingGroupSize() <= 1) return false;
630             if (e2().bindingGroupSize() <= 1) return false;
631             if (e3().bindingGroupSize() <= 1) return false;
632             */
633             return true;
634         }
635
636         /** issue gl.glVertex() for each of the triangle's points */
637         public void glVertices(GL gl) {
638             if (!shouldBeDrawn()) return;
639             norm().glNormal(gl);
640             Point p1 = v1().goodp;
641             Point p2 = v2().goodp;
642             Point p3 = v3().goodp;
643             p1.glVertex(gl);
644             p2.glVertex(gl);
645             p3.glVertex(gl);
646         }
647
648     }
649 }