1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
4 /** any object associated with a specific point in 3D space */
5 public abstract class HasQuadric extends HasPoint {
7 public float oldscore = 0;
8 public Matrix errorQuadric() { return quadric; }
9 public boolean quadricStale = false;
10 /** the nearest vertex in the "score_against" mesh */
11 public HasQuadric nearest_in_other_mesh;
13 /** the number of vertices in the other mesh for which this is the nearest_in_other_mesh */
14 public int quadric_count;
16 /** the total error quadric (contributions from all vertices in other mesh for which this is nearest) */
17 public Matrix quadric = Matrix.ZERO;
19 public Matrix fundamentalQuadric = null;
21 public void recomputeFundamentalQuadricIfNeighborChanged() {
22 HasQuadric oldv = nearest_in_other_mesh;
23 HasQuadric newv = nearest();
24 if (oldv==newv) return;
25 recomputeFundamentalQuadric();
26 if (oldv!=null) oldv.recomputeFundamentalQuadricIfNeighborChanged();
27 // for some reason this causes an infinite loop
28 //if (newv!=null) newv.recomputeFundamentalQuadricIfNeighborChanged();
30 public void recomputeFundamentalQuadricIfStale() {
31 if (quadricStale || fundamentalQuadric==null)
32 recomputeFundamentalQuadric();
34 public abstract void recomputeFundamentalQuadric();
35 public abstract void applyQuadricToNeighbor();
36 public abstract void reComputeErrorAround();
37 public abstract void reComputeError();
38 public abstract void unComputeError();
39 public abstract void computeError();
40 public abstract HasQuadric nearest();
41 public Matrix fundamentalQuadric() {
42 if (fundamentalQuadric == null) recomputeFundamentalQuadric();
43 return fundamentalQuadric;
45 public void unApplyQuadricToNeighbor() {
46 if (nearest_in_other_mesh == null) return;
47 if (fundamentalQuadric == null) return;
48 nearest_in_other_mesh.unComputeError();
49 nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.minus(fundamentalQuadric);
50 nearest_in_other_mesh.quadric_count--;
51 if (nearest_in_other_mesh.quadric_count==0)
52 nearest_in_other_mesh.quadric = Matrix.ZERO;
53 nearest_in_other_mesh.computeError();
54 nearest_in_other_mesh = null;