}
}
- public void unscore() {
+ public void unApplyQuadricToNeighborAll() {
HashSet<Vert> done = new HashSet<Vert>();
for(T t : this)
for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() }) {
if (done.contains(p)) continue;
done.add(p);
- p.unscore();
+ p.unApplyQuadricToNeighbor();
}
}
public void recomputeAllFundamentalQuadrics() {
p.recomputeFundamentalQuadric();
}
}
- public float rescore() {
+ public float applyQuadricToNeighborAll() {
int num = 0;
double dist = 0;
HashSet<Vert> done = new HashSet<Vert>();
for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() }) {
if (done.contains(p)) continue;
done.add(p);
- p.rescore();
+ p.applyQuadricToNeighbor();
}
return (float)(dist/num);
}
}
+ public void rebuildPointSet() { pointset.rebuild(); }
public Vec diagonal() { return pointset.diagonal(); }
public Point centroid() { return pointset.centroid(); }
public Vert nearest(Point p) { return pointset.nearest(p); }
Vert bound_to = this;
Matrix binding = new Matrix();
float oldscore = 0;
+ boolean quadricStale = false;
public Matrix errorQuadric() { return quadric; }
public Point getPoint() { return p; }
}
public void recomputeFundamentalQuadric() {
- unscore();
+ if (!quadricStale && fundamentalQuadric != null) return;
+ quadricStale = false;
+ unApplyQuadricToNeighbor();
Matrix m = Matrix.ZERO;
E e = this.e;
do {
e = e.pair.next;
} while(e != this.e);
fundamentalQuadric = m;
- rescore();
+ applyQuadricToNeighbor();
}
- public void unscore() {
+ 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;
}
- public void rescore() {
+ public void applyQuadricToNeighbor() {
if (score_against == null) return;
- score -= oldscore;
- oldscore = 0;
+ Vert new_nearest = score_against.nearest(p);
+ if (nearest_in_other_mesh != null && new_nearest == nearest_in_other_mesh) return;
- if (nearest_in_other_mesh != null) unscore();
- if (nearest_in_other_mesh == null) {
- nearest_in_other_mesh = score_against.nearest(p);
+ if (nearest_in_other_mesh != null) unApplyQuadricToNeighbor();
+ if (nearest_in_other_mesh != null) throw new Error();
- // don't attract to vertices that face the other way
- if (nearest_in_other_mesh.e == null || nearest_in_other_mesh.norm().dot(norm()) < 0) {
- nearest_in_other_mesh = null;
- } else {
- nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric());
- nearest_in_other_mesh.quadric_count++;
- }
+ nearest_in_other_mesh = new_nearest;
+
+ // don't attract to vertices that face the other way
+ if (nearest_in_other_mesh.e == null || nearest_in_other_mesh.norm().dot(norm()) < 0) {
+ nearest_in_other_mesh = null;
+ } else {
+ 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 void reComputeError() {
+ unComputeError();
+ computeError();
+ }
+ public void unComputeError() {
+ score -= oldscore;
+ oldscore = 0;
+ }
+ public void computeError() {
oldscore = quadric_count == 0 ? 0 : (quadric.preAndPostMultiply(p) / quadric_count);
score += oldscore;
}
/** does NOT update bound pairs! */
public boolean transform(Matrix m) {
- unscore();
+ unApplyQuadricToNeighbor();
try {
if (pointset.get(this.p)==null) throw new Error();
pointset.remove(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
- rescore();
+ applyQuadricToNeighbor();
// should recompute fundamental quadrics of all vertices sharing a face, but we defer...
+ E e = this.e;
+ do {
+ e.p2.quadricStale = true;
+ e = e.pair.next;
+ } while(e != this.e);
+
+
// FIXME: intersection test needed?
return true;
}