X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FHasQuadric.java;h=e358e69663c87ea992d213c6d6d3a9ea26217c46;hp=8addfc23099625a783e094877968af36c35486ef;hb=87e7ecfbdce5f5ecb16cd911f21890ccbaf4679c;hpb=0333b4f07d3e3cacb5975fe7ac3c8c3933150e37 diff --git a/src/edu/berkeley/qfat/geom/HasQuadric.java b/src/edu/berkeley/qfat/geom/HasQuadric.java index 8addfc2..e358e69 100644 --- a/src/edu/berkeley/qfat/geom/HasQuadric.java +++ b/src/edu/berkeley/qfat/geom/HasQuadric.java @@ -4,7 +4,6 @@ import javax.media.opengl.*; /** any object associated with a specific point in 3D space */ public abstract class HasQuadric extends HasPoint { - public float oldscore = 0; public Matrix errorQuadric() { return quadric; } public boolean quadricStale = false; /** the nearest vertex in the "score_against" mesh */ @@ -18,61 +17,66 @@ public abstract class HasQuadric extends HasPoint { public Matrix fundamentalQuadric = null; - public void recomputeFundamentalQuadricIfNeighborChanged() { - HasQuadric oldv = nearest_in_other_mesh; - HasQuadric newv = nearest(); - if (oldv==newv) return; + public void recomputeFundamentalQuadricIfNeighborChanged() { + HasQuadric oldv = nearest_in_other_mesh; + HasQuadric newv = nearest(); + if (oldv==newv) return; + recomputeFundamentalQuadric(); + if (oldv!=null) oldv.recomputeFundamentalQuadricIfNeighborChanged(); + // for some reason this causes an infinite loop + //if (newv!=null) newv.recomputeFundamentalQuadricIfNeighborChanged(); + } + public void recomputeFundamentalQuadricIfStale() { + if (quadricStale || fundamentalQuadric==null) recomputeFundamentalQuadric(); - if (oldv!=null) oldv.recomputeFundamentalQuadricIfNeighborChanged(); - // for some reason this causes an infinite loop - //if (newv!=null) newv.recomputeFundamentalQuadricIfNeighborChanged(); + } + public void recomputeFundamentalQuadric() { + unApplyQuadricToNeighbor(); + if (quadricStale || fundamentalQuadric==null) { + fundamentalQuadric = _recomputeFundamentalQuadric(); + quadricStale = false; } - public void recomputeFundamentalQuadricIfStale() { - if (quadricStale || fundamentalQuadric==null) - recomputeFundamentalQuadric(); + applyQuadricToNeighbor(); + } + public abstract Matrix _recomputeFundamentalQuadric(); + public void reComputeError() { + unComputeError(); + computeError(); } - public void recomputeFundamentalQuadric() { - unApplyQuadricToNeighbor(); - if (quadricStale || fundamentalQuadric==null) _recomputeFundamentalQuadric(); - applyQuadricToNeighbor(); - } - public abstract void _recomputeFundamentalQuadric(); - public abstract void reComputeErrorAround(); - public abstract void reComputeError(); public abstract void unComputeError(); public abstract void computeError(); public abstract HasQuadric nearest(); - public void applyQuadricToNeighbor() { - HasQuadric new_nearest = nearest(); - if (nearest_in_other_mesh != null && new_nearest == nearest_in_other_mesh) return; - - if (nearest_in_other_mesh != null) unApplyQuadricToNeighbor(); - if (nearest_in_other_mesh != null) throw new Error(); + public void applyQuadricToNeighbor() { + HasQuadric new_nearest = nearest(); + if (nearest_in_other_mesh != null && new_nearest == nearest_in_other_mesh) return; - nearest_in_other_mesh = new_nearest; + if (nearest_in_other_mesh != null) unApplyQuadricToNeighbor(); + if (nearest_in_other_mesh != null) throw new Error(); - if (nearest_in_other_mesh!=null) { - nearest_in_other_mesh.unComputeError(); - nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric()); - nearest_in_other_mesh.quadric_count++; - nearest_in_other_mesh.computeError(); - } + nearest_in_other_mesh = new_nearest; - reComputeError(); - } - public Matrix fundamentalQuadric() { - if (fundamentalQuadric == null) recomputeFundamentalQuadric(); - return fundamentalQuadric; - } - public void unApplyQuadricToNeighbor() { - if (nearest_in_other_mesh == null) return; - if (fundamentalQuadric == null) return; + if (nearest_in_other_mesh!=null) { nearest_in_other_mesh.unComputeError(); - nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.minus(fundamentalQuadric); - nearest_in_other_mesh.quadric_count--; - if (nearest_in_other_mesh.quadric_count==0) - nearest_in_other_mesh.quadric = Matrix.ZERO; + nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric()); + nearest_in_other_mesh.quadric_count++; nearest_in_other_mesh.computeError(); - nearest_in_other_mesh = null; } + + reComputeError(); + } + public Matrix fundamentalQuadric() { + if (fundamentalQuadric == null) recomputeFundamentalQuadric(); + return fundamentalQuadric; + } + public void unApplyQuadricToNeighbor() { + if (nearest_in_other_mesh == null) return; + if (fundamentalQuadric == null) return; + nearest_in_other_mesh.unComputeError(); + nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.minus(fundamentalQuadric); + nearest_in_other_mesh.quadric_count--; + if (nearest_in_other_mesh.quadric_count==0) + nearest_in_other_mesh.quadric = Matrix.ZERO; + nearest_in_other_mesh.computeError(); + nearest_in_other_mesh = null; + } }