X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMain.java;h=9cbffcf75cd6c7ea87bd14a43ee694f271b5bacb;hb=95776aa09a9b304bc7599b81699b595fdecd1f3a;hp=65c6c2abfc36793fa7a6b19f79d508ab599c4915;hpb=e3aa83b5505dcfbc200e29e5b1701664bb218709;p=anneal.git diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 65c6c2a..9cbffcf 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -5,6 +5,8 @@ import javax.swing.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import java.util.*; +import edu.berkeley.qfat.geom.*; +import edu.berkeley.qfat.geom.Point; // FIXME: recenter goal to have centroid coincident with tile // FIXME: re-orient goal (how?) @@ -17,7 +19,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener boolean control = false; public void mouseWheelMoved(MouseWheelEvent e) { - tz -= e.getWheelRotation() ; + tz -= e.getWheelRotation(); } public void keyTyped(KeyEvent e) { } @@ -66,70 +68,70 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener mousey = e.getY(); } - private Geom tile = new Geom(); - private Geom goal = new Geom(); + private Mesh tile = new Mesh(); + private Mesh goal = new Mesh(); /** magnification factor */ private static final float MAG = 1; - Geom.M[] translations; - Geom.V[] points; + Matrix[] translations; + Mesh.Vert[] points; public Main(StlFile stlf) { for(int i=0; i 300) return; + if (verts > 200) return; //double min = (tile.avgedge/tile.numedges)*(1+(4/(double)verts)); //if (verts>0 && tile.es.peek().length() < min) return; - PriorityQueue es = new PriorityQueue(); - for(Geom.E e : tile.es) es.add(e); + PriorityQueue es = new PriorityQueue(); + for(Mesh.E e : tile.edges()) es.add(e); for(int i=0; i<10; i++) { - Geom.E e = es.poll(); + Mesh.E e = es.poll(); verts++; System.out.println("shatter " + e); e.shatter(); @@ -252,28 +254,40 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener } } - public synchronized void rand(double temperature, Geom.V p) { + public synchronized void rand(double temperature, Mesh.Vert p) { double tile_score = tile.score(); double goal_score = goal.score(); - p.rescore(); + + /* //if (p.watch==null) return; float r1 = Math.abs(random.nextFloat()); r1 = r1 - (float)Math.floor(r1); r1 = r1 * (float)0.01; r1 = r1 - (float)0.005; - Geom.Vec v = p.watchback().p.minus(p.p).norm().times(r1); + public Vert partner() { return quadric==null ? this : quadric; } + public Point quadric() { return quadric_count==0 ? partner().p : + new Point(quadric_x/quadric_count, quadric_y/quadric_count, quadric_z/quadric_count); } + Vec v = p.nearest_vert_in_other_mesh().minus(p.p).norm().times(r1); + */ //v = p.norm().times(v.dot(p.norm())); + /* + Vec v = new Vec((random.nextFloat() - (float)0.5) / 1000, + (random.nextFloat() - (float)0.5) / 1000, + (random.nextFloat() - (float)0.5) / 1000); + */ + Matrix inv = p.errorQuadric(); + Vec v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000); boolean aspect = false;//(Math.abs(random.nextInt()) % 100) <= 2; - Geom.M old_tile_aspect = null;//goal.aspect; + Matrix old_tile_aspect = null;//goal.aspect; boolean good = true; if (aspect) { /* v = v.times(10); - tile.aspect = new Geom.M(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1)); - tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k); + tile.aspect = new Matrix(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1)); + tile.invaspect = new Matrix(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k); goal.rescore(); tile.rescore(); */ @@ -288,6 +302,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener double swapProbability = Math.exp((-1 * delta) / temperature); //boolean doSwap = Math.random() < swapProbability; boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0); + //System.out.println(doSwap); if (doSwap) { tile_score = new_tile_score; goal_score = new_goal_score; @@ -296,7 +311,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener } else { if (aspect) { //tile.aspect = old_tile_aspect; - //tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k); + //tile.invaspect = new Matrix(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k); goal.rescore(); tile.rescore(); } else { @@ -348,12 +363,12 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener int i = 0; //gl.glDisable(GL.GL_DEPTH_TEST); gl.glColor4f(1,1,1,1); - for(Geom.M m : translations) { + for(Matrix m : translations) { //if (v1.z==0 && v1.y==0) continue; i++; if (i != 1 /*&& i!=4*/) continue; - Geom.P p = new Geom.P(0, 0, 0).times(m); - Geom.Vec v = new Geom.Vec(p.x, p.y, p.z); + Point p = new Point(0, 0, 0).times(m); + Vec v = new Vec(p.x, p.y, p.z); v = v.times((float)1.04); gl.glTranslatef(v.x, v.y, v.z); draw(gl, false, tile); @@ -362,11 +377,11 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener //gl.glEnable(GL.GL_DEPTH_TEST); } - private synchronized void draw(GL gl, boolean triangles, Geom mesh) { + private synchronized void draw(GL gl, boolean triangles, Mesh mesh) { float red = 0.0f; float green = 0.0f; float blue = 0.0f; - for(Geom.T t : mesh) { + for(Mesh.T t : mesh) { if (red < 0.15) red = 1.0f; if (green < 0.15) green = 1.0f; if (blue < 0.15) blue = 1.0f; @@ -397,7 +412,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener gl.glEnd(); } - Geom.P centroid = t.centroid(); + Point centroid = t.centroid(); gl.glBegin(GL.GL_LINES); gl.glColor3f(1, 1, 1); /* @@ -406,10 +421,10 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener */ if (mesh==goal) - for(Geom.V p : new Geom.V[] { t.p1(), t.p2(), t.p3() }) { + for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) { p.p.glVertex(gl); //p.plus(p.norm().times(p.score()*10)).glVertex(gl); - p.partner().p.glVertex(gl); + //p.partner().p.glVertex(gl); //tile.nearest(p).centroid().glVertex(gl); } @@ -447,8 +462,8 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener for(int i=0; i<1; i++) { glcanvas.repaint(); //tile.ts.get(Math.abs(random.nextInt()) % tile.ts.size()).e1().p1 - for(Geom.T t : tile) - for(Geom.V p : new Geom.V[] { t.p1(), t.p2(), t.p3() }) { + for(Mesh.T t : tile) + for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) { rand(10,p); } goal.rescore();