From: adam Date: Mon, 30 Jun 2008 03:24:23 +0000 (-0700) Subject: checkpoint X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=0c83217e7d2c100185cca08f5fcd310f2a5347a1 checkpoint darcs-hash:20080630032423-5007d-c96b492d62dfaf0180cf35fa5fe79c855dde679e.gz --- diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 2a1584e..3ce1d88 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -52,6 +52,7 @@ import edu.berkeley.qfat.geom.Polygon; public class Main extends InteractiveMeshViewer { + public static int verts = 1; public static final Random random = new Random(); @@ -135,8 +136,7 @@ public class Main extends InteractiveMeshViewer { public Main(JFrame f) { super(f); } - public void fixupTile() { - synchronized(safeTriangles) { + public synchronized void fixupTile() { for(Matrix m1 : transforms) { for(Matrix m2 : transforms) { if (m1==m2) continue; @@ -199,7 +199,6 @@ public class Main extends InteractiveMeshViewer { tile.error_against = goal; goal.error_against = tile; fixupGoal(); - } } public void breakit() { @@ -236,8 +235,7 @@ public class Main extends InteractiveMeshViewer { Vec v = new Vec(random.nextFloat(), random.nextFloat(), random.nextFloat()); v = v.norm().times((random.nextFloat() - 0.5f) * max); Matrix m = Matrix.translate(v); - - boolean good = p.move(m, false); + boolean good = p.move(v, false); if (!good) { return false; } double new_tile_error = tile.error(); @@ -263,7 +261,7 @@ public class Main extends InteractiveMeshViewer { hits++; p.goodp = p.p; } else { - p.move(Matrix.translate(v.times(-1)), true); + p.move(v.times(-1), true); misses++; } p.reComputeErrorAround(); @@ -280,13 +278,7 @@ public class Main extends InteractiveMeshViewer { double acceptance = 1; while(true) { synchronized(this) { - synchronized(safeTriangles) { - safeTriangles.clear(); - for(Mesh.T t : tile) - if (t.shouldBeDrawn()) - safeTriangles.add(t); - } - if (!anneal) { repaint(); Thread.sleep(10); continue; } + if (!anneal) { repaint(); Thread.sleep(10); continue; } double ratio = (hits+misses==0) ? 1 : (hits / (hits+misses)); hits = 0; @@ -371,9 +363,7 @@ public class Main extends InteractiveMeshViewer { } public void actionPerformed(ActionEvent event) { synchronized(Main.this) { - synchronized(safeTriangles) { hit(); - } } } public void hit() {} @@ -863,6 +853,7 @@ public class Main extends InteractiveMeshViewer { Matrix.translate(new Vec(-0.2f,0,0)) .times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))), + //Matrix.rotate(new Vec(0,0,1), (float)(1*Math.PI/2)), /* diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index d56e2a0..823f07c 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -247,7 +247,7 @@ public class Mesh implements Iterable { setError(nerror); } - public boolean move(Matrix m, boolean ignoreProblems) { + public boolean move(Vec vv, boolean ignoreProblems) { boolean good = true; @@ -258,21 +258,26 @@ public class Mesh implements Iterable { // M * t1 = M * t1.getMatrix(t2) * t2 if (bindingGroup!=null && this != bindingGroup.getMaster()) { - Matrix v = getBindingMatrix(bindingGroup.getMaster()); - return ((Vertex)bindingGroup.getMaster()).move(v.inverse().times(m).times(v), ignoreProblems); + Matrix m2 = getBindingMatrix(bindingGroup.getMaster()); + Vec v2 = m2.times(vv.plus(getPoint())).minus(m2.times(getPoint())); + return ((Vertex)bindingGroup.getMaster()).move(v2, ignoreProblems); } + Point op = this.p; + Point pp = vv.plus(getPoint()); if (bindingGroup != null) { - Matrix m2 = null; - for(int i=0; i<20 && !m.equals(m2); i++) { - m2 = m.times(getConstraint()); + /* + for(int i=0; i<20 ; i++) { + Point p2 = getConstraint().times(pp); + pp = pp.midpoint(p2); //System.out.println(m.minus(m2)); } - if (!m.equals(m2)) return true; + */ + pp = getConstraint().times(pp); } + pp = pp.minus(op).norm().times(vv.mag()).plus(op); ok = false; - Point op = this.p; - Point pt = m.times(this.p); + Point pt = pp; for(Vertex v : (Iterable)getBoundPeers()) { Point pt2 = v.getBindingMatrix(this).times(pt); /* @@ -304,7 +309,6 @@ public class Mesh implements Iterable { unApplyQuadricToNeighbor(); - boolean illegalbefore = illegal; illegal = false; /* diff --git a/src/edu/berkeley/qfat/MeshViewer.java b/src/edu/berkeley/qfat/MeshViewer.java index 3f57d77..3751ddf 100644 --- a/src/edu/berkeley/qfat/MeshViewer.java +++ b/src/edu/berkeley/qfat/MeshViewer.java @@ -33,7 +33,6 @@ public class MeshViewer extends Viewer { public int temps; public int accepts; public int vertss; - protected HashSet safeTriangles = new HashSet(); public MeshViewer(JFrame f) { super(f); } @@ -47,6 +46,7 @@ public class MeshViewer extends Viewer { gl.glPointSize(5.0f); gl.glLoadIdentity(); glu.gluPerspective(50, ((float)drawable.getWidth())/drawable.getHeight(), 0.5, 10); + glu.gluLookAt(0, 0, -((tz/10)-1), 0, 0, 0, 0, 1, 0); gl.glRotatef(anglex/3, 0, 1, 0); gl.glRotatef(-(angley/3), 1, 0, 0); @@ -54,15 +54,7 @@ public class MeshViewer extends Viewer { tile.render(gl, Matrix.ONE); goal.render(gl, Matrix.ONE); - int i = 0; - gl.glColor4f(1,1,1,1); - for(Matrix m : transforms) { - i++; - if (neighborsWireOne && i!=whichNeighbor) continue; - if (neighbors) tile.render(gl, m); - else if (neighborsWire || neighborsWireOne) tile.render(gl, m); - } - + // highlight the point closest to the mouse gl.glDisable(GL.GL_LIGHTING); gl.glShadeModel(GL.GL_FLAT); if (closest != null) { @@ -72,18 +64,22 @@ public class MeshViewer extends Viewer { gl.glEnd(); } + // update vertex visibilities + // FIXME: only do this when we switch into vertex-finding mode updateVisibility(gl, tile); Matrix projection = Matrix.getProjectionMatrix(gl); double dist = Double.MAX_VALUE; - if (clickPoint != null) return; + if (getMouseClick() != null) return; closest = null; for(Mesh.Vertex v : tile.vertices()) { if (!v.visible) continue; Point p = projection.times(v.getPoint()); int x = (int)p.x; int y = (int)p.y; - y = glcanvas.getHeight()-y; + //y = glcanvas.getHeight()-y; + int mousex = (int)getMouse().x; + int mousey = (int)getMouse().y; if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) { dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey); closest = v; diff --git a/src/edu/berkeley/qfat/Viewer.java b/src/edu/berkeley/qfat/Viewer.java index 89ba7b3..1464020 100644 --- a/src/edu/berkeley/qfat/Viewer.java +++ b/src/edu/berkeley/qfat/Viewer.java @@ -18,17 +18,16 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot public Mesh tile = new Mesh(false); public Mesh goal = new Mesh(false); + private int mousex; + private int mousey; private Matrix projection = null; JFrame f; GLCanvas glcanvas; - Point clickPoint = null; + + private Point clickPoint = null; Point clickClosest = null; - int mousex; - int mousey; - float tx = 0; - float ty = 0; float tz = 0; float anglex = 0; float angley = 0; @@ -119,12 +118,16 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot gl.glDrawBuffer(GL.GL_FRONT); } - /** return the position of the mouse as a point in window-space */ public Point getMouse() { return new Point(mousex, glcanvas.getHeight()-mousey, 0); } + /** return the position where the mouse button was pressed, or null if it is not currently pressed */ + public Point getMouseClick() { + return clickPoint; + } + public void mouseWheelMoved(MouseWheelEvent e) { tz -= e.getWheelRotation(); } @@ -166,17 +169,11 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot public void mouseDragged(MouseEvent e) { if (shift) { - /* - tx += (mousex - e.getX())/(float)20; - ty += (mousey - e.getY())/(float)20; - */ if (closest != null && projection != null && clickClosest != null) { synchronized(this) { Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint)); Vec delta = d1.plus(clickClosest).minus(closest.getPoint()); - //System.out.println(delta + " " + closest.getPoint()); - System.out.println(getMouse().minus(clickPoint)); - closest.move(Matrix.translate(delta), false); + closest.move(delta, false); } } } else { diff --git a/src/edu/berkeley/qfat/geom/Point.java b/src/edu/berkeley/qfat/geom/Point.java index f46cc7e..1a4ac79 100644 --- a/src/edu/berkeley/qfat/geom/Point.java +++ b/src/edu/berkeley/qfat/geom/Point.java @@ -14,6 +14,7 @@ public final class Point implements HasBoundingBox { public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); } public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); } + public Point midpoint(Point p) { return new Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2); } public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }