X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMain.java;h=2fbd7261b421ef32c5f46cd976d9d0645d715af5;hp=b774066000443e5e9cb28c6922b12f1e56006e14;hb=6fe08d5c50c341f47ded8ce9acd670aad9362614;hpb=b6875b8bd79c804e15eb75bc64044ca2c770b07d diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index b774066..2fbd726 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -8,139 +8,152 @@ 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?) -// fish case: ensure that spinal axis of fish is the x-axis of the tile +// TO DO: +// - real anneal +// - solve self-intersection problem +// - get a better test model? +// - symmetry constraints withing the tile +// - rotation matrices +// - overbinding results in forced equational constraints on the leader +// - shatter in invertd-triforce pattern brian mentioned +// - aspect ratio? non-uniform deformation? +// - rotational alignment + +// - movie-style user interface like +// http://www.coleran.com/markcoleranreell.html ? + +// - consider recasting the Shewchuk predicates in Java? +// http://www.cs.cmu.edu/afs/cs/project/quake/public/code/predicates.c + +/* +blender keys +- middle mouse = option+click +- right mouse = command+click + +3,7,1 = view along axes (control for opp direction) +4, 8, 7, 2 = rotate in discrete increments (+control to translate) +middle trag: rotate space +shift+middle drag: translate space +wheel: zoom +home: home view: take current angle, zoom to whole scnee +5 = ortho vs non-ortho + + */ -public class Main implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener { - - boolean alt = false; - boolean shift = false; - boolean control = false; - public void mouseWheelMoved(MouseWheelEvent e) { - tz -= e.getWheelRotation(); - } +// FIXME: re-orient goal (how?) - public void keyTyped(KeyEvent e) { } - public void keyPressed(KeyEvent e) { - switch(e.getKeyCode()) { - case KeyEvent.VK_CONTROL: control = true; break; - case KeyEvent.VK_ALT: alt = true; break; - case KeyEvent.VK_SHIFT: shift = true; break; - } - } - public void keyReleased(KeyEvent e) { - switch(e.getKeyCode()) { - case KeyEvent.VK_CONTROL: control = false; break; - case KeyEvent.VK_ALT: alt = false; break; - case KeyEvent.VK_SHIFT: shift = false; break; - } - } +public class Main extends MeshViewer { - public void mouseClicked(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) { } - public void mousePressed(MouseEvent e) { } - public void mouseReleased(MouseEvent e) { } - - int mousex; - int mousey; - public void mouseMoved(MouseEvent e) { - mousex = e.getX(); - mousey = e.getY(); - } - - float tx = 0; - float ty = 0; - float tz = 0; - float anglex = 0; - float angley = 0; - public void mouseDragged(MouseEvent e) { - if (shift) { - tx += (mousex - e.getX())/(float)20; - ty += (mousey - e.getY())/(float)20; - } else { - anglex -= mousex - e.getX(); - angley += mousey - e.getY(); - } - mousex = e.getX(); - mousey = e.getY(); - } - - private Mesh tile = new Mesh(); - private Mesh goal = new Mesh(); + public static int verts = 1; + public static final Random random = new Random(); + /** magnification factor */ private static final float MAG = 1; - Matrix[] translations; - Mesh.Vert[] points; - - public Main(StlFile stlf) { + public Main(StlFile stlf, Frame f) { + super(f); for(int i=0; i 300) return; - //double min = (tile.avgedge/tile.numedges)*(1+(4/(double)verts)); - //if (verts>0 && tile.es.peek().length() < min) return; + int oldverts = verts; + System.out.println("doubling vertices."); PriorityQueue es = new PriorityQueue(); - for(Mesh.E e : tile.edges()) es.add(e); - for(int i=0; i<10; i++) { + for(Mesh.T t : tile) { + es.add(t.e1()); + es.add(t.e2()); + es.add(t.e3()); + } + for(int i=0; i 0) { while (breaks>0) { + breaks--; + breakit(); + //gamma = 1; + gamma = 1; + //temp = last * 0.8f; + //last = temp; + //temp = hightemp; + } } else + if (acceptance > 0.96) gamma = 0.4f; + else if (acceptance > 0.9) gamma = 0.5f; + else if (acceptance > 0.8) gamma = 0.65f; + else if (acceptance > 0.6) gamma = 0.7f; + else { + if (acceptance > 0.3) { + gamma = 0.9f; + } else if (acceptance > 0.15) { + gamma = 0.95f; + } else if (acceptance > 0.10) { + gamma = 0.98f; + } else { + breakit(); + //gamma = 1; + gamma = 0.99f; + //gamma = 1; + //temp = last * 0.8f; + //last = temp; + //temp = hightemp; + } } + temp = temp * gamma; - Point centroid = t.centroid(); - gl.glBegin(GL.GL_LINES); - gl.glColor3f(1, 1, 1); - /* - centroid.glVertex(gl); - centroid.plus(t.norm().times(t.diameter())).glVertex(gl); - */ - - if (mesh==goal) - 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); - //tile.nearest(p).centroid().glVertex(gl); - } - gl.glEnd(); + HashSet hs = new HashSet(); + for(Mesh.Vertex p : tile.vertices()) hs.add(p); + Mesh.Vertex[] pts = (Mesh.Vertex[])hs.toArray(new Mesh.Vertex[0]); - } + int count = 0; + long then = System.currentTimeMillis(); + for(int i=0; i<40; i++) { + if (anneal) { + count++; + Mesh.Vertex v = pts[Math.abs(random.nextInt()) % pts.length]; + rand(temp,v); + } + Thread.yield(); + repaint(); + } + System.out.println("temp="+temp + " ratio="+(Math.ceil(ratio*100)) + " " + + "points_per_second=" + + (count*1000)/((double)(System.currentTimeMillis()-then))); + + for(Mesh.Vertex p : tile.vertices()) p.recomputeFundamentalQuadric(); + repaint(); + for(Mesh.Vertex p : goal.vertices()) p.recomputeFundamentalQuadric(); + repaint(); + + synchronized(safeTriangles) { + safeTriangles.clear(); + for(Mesh.T t : tile) if (t.shouldBeDrawn()) safeTriangles.add(t); + } + } + } } + public static void main(String[] s) throws Exception { StlFile stlf = new StlFile(); - stlf.load("simplefish.stl"); - Main main = new Main(stlf); + stlf.load("fish.stl"); + //stlf.load("monkey.stl"); Frame f = new Frame(); - GLCapabilities glcaps = new GLCapabilities(); - GLCanvas glcanvas = new GLCanvas(); - glcanvas.addGLEventListener(main); - f.add(glcanvas, BorderLayout.CENTER); + Main main = new Main(stlf, f); f.pack(); f.show(); f.setSize(900, 900); f.doLayout(); - - glcanvas.addMouseListener(main); - glcanvas.addMouseMotionListener(main); - glcanvas.addMouseWheelListener(main); - glcanvas.addKeyListener(main); - - main.anneal(glcanvas); - } - public static int verts = 0; - public void anneal(GLCanvas glcanvas) throws Exception { - int verts = 0; - while(true) { - //Thread.sleep(10); - for(int i=0; i<1; i++) { - glcanvas.repaint(); - //tile.ts.get(Math.abs(random.nextInt()) % tile.ts.size()).e1().p1 - for(Mesh.T t : tile) - for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) { - rand(10,p); - } - goal.rescore(); - tile.rescore(); - } - breakit(); - } - + main.anneal(); } } \ No newline at end of file