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 void recomputeFundamentalQuadric() {
35 unApplyQuadricToNeighbor();
36 if (quadricStale || fundamentalQuadric==null) _recomputeFundamentalQuadric();
37 applyQuadricToNeighbor();
39 public abstract void _recomputeFundamentalQuadric();
40 public abstract void applyQuadricToNeighbor();
41 public abstract void reComputeErrorAround();
42 public abstract void reComputeError();
43 public abstract void unComputeError();
44 public abstract void computeError();
45 public abstract HasQuadric nearest();
46 public Matrix fundamentalQuadric() {
47 if (fundamentalQuadric == null) recomputeFundamentalQuadric();
48 return fundamentalQuadric;
50 public void unApplyQuadricToNeighbor() {
51 if (nearest_in_other_mesh == null) return;
52 if (fundamentalQuadric == null) return;
53 nearest_in_other_mesh.unComputeError();
54 nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.minus(fundamentalQuadric);
55 nearest_in_other_mesh.quadric_count--;
56 if (nearest_in_other_mesh.quadric_count==0)
57 nearest_in_other_mesh.quadric = Matrix.ZERO;
58 nearest_in_other_mesh.computeError();
59 nearest_in_other_mesh = null;