X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FHasQuadric.java;h=1c8d6553e2c18a675d9894be82dafb92185aedd9;hp=825bda9c9a0e9782ab6aa8bad8b48b52aacb1e42;hb=eabe4f7acd947415f183290dc3269b2502a25a1c;hpb=485efa58c987b9a4b5155b36ae7c64eff4251142 diff --git a/src/edu/berkeley/qfat/geom/HasQuadric.java b/src/edu/berkeley/qfat/geom/HasQuadric.java index 825bda9..1c8d655 100644 --- a/src/edu/berkeley/qfat/geom/HasQuadric.java +++ b/src/edu/berkeley/qfat/geom/HasQuadric.java @@ -17,29 +17,67 @@ 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(); - } - public abstract void recomputeFundamentalQuadric(); - public abstract void unApplyQuadricToNeighbor(); - public abstract void applyQuadricToNeighbor(); - public abstract void reComputeErrorAround(); - public abstract void reComputeError(); - public abstract void unComputeError(); + applyQuadricToNeighbor(); + } + public abstract Matrix _recomputeFundamentalQuadric(); + public void unComputeError() { setError(0); } + public void reComputeError() { + unComputeError(); + computeError(); + } + public abstract void setError(float nerror); public abstract void computeError(); public abstract HasQuadric nearest(); - public Matrix fundamentalQuadric() { - if (fundamentalQuadric == null) recomputeFundamentalQuadric(); - return fundamentalQuadric; + 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(); + + nearest_in_other_mesh = new_nearest; + + 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(); } + + 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; + } }