X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FInteractiveMeshViewer.java;h=ed238032db23e0dbf999db83a34215437471ce8c;hp=10ec04516639171ce43c3eea88c54c0d82148121;hb=076fc38f95ee874e4bb01e03cb1021f5d137f35e;hpb=689c6bb1f140c8aeecec459c4c85264b4d3c7255 diff --git a/src/edu/berkeley/qfat/InteractiveMeshViewer.java b/src/edu/berkeley/qfat/InteractiveMeshViewer.java index 10ec045..ed23803 100644 --- a/src/edu/berkeley/qfat/InteractiveMeshViewer.java +++ b/src/edu/berkeley/qfat/InteractiveMeshViewer.java @@ -13,6 +13,84 @@ import edu.berkeley.qfat.geom.Point; public class InteractiveMeshViewer extends MeshViewer { - public InteractiveMeshViewer(JFrame f) { super(f); } + public Mesh tile; + public Mesh goal; + public InteractiveMeshViewer(JFrame f) { + super(f); + setTile(new Mesh(false)); + setGoal(new Mesh(false)); + } + + public void setTile(Mesh tile) { + removeMesh(this.tile); + this.tile = tile; + addMesh(this.tile); + } + public void setGoal(Mesh goal) { + removeMesh(this.goal); + this.goal = goal; + goal.option_selectable = false; + goal.option_wireframe = true; + addMesh(this.goal); + } + + public synchronized void dump() { + try { + PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("dump.stl"))); + pw.println("solid dump"); + for(Mesh.T t : tile) { + Vec normal = t.norm(); + pw.println("facet normal " + normal.x + " " + normal.y + " " + normal.z); + pw.println(" outer loop"); + for(Mesh.Vertex v : new Mesh.Vertex[] { t.v1(), t.v2(), t.v3() }) { + pw.println(" vertex " + v.p.x + " " + v.p.y + " " + v.p.z); + } + pw.println(" endloop"); + pw.println("endfacet"); + } + pw.println("endsolid dump"); + pw.flush(); + pw.close(); + } catch (Exception e) { throw new RuntimeException(e); } + } + + public int whichNeighbor = 1; + public double temp; + public boolean tileon = true; + public boolean tilemeshon = false; + public boolean goalon = true; + public boolean anneal = false; + public boolean hillclimb = false; + public boolean neighbors = false; + public boolean neighborsWire = false; + public boolean neighborsWireOne = false; + public boolean errorNormals = false; + + public boolean force = false; + public Mesh.Vertex[] points; + public int breaks = 0; + + public int temps; + public int accepts; + public int vertss; + + public void keyPressed(KeyEvent e) { + super.keyPressed(e); + switch(e.getKeyCode()) { + case KeyEvent.VK_SPACE: breaks++; force = true; break; + case KeyEvent.VK_UP: temp = temp * 2; break; + case KeyEvent.VK_ENTER: temp = 10; break; + case KeyEvent.VK_LEFT: whichNeighbor--; break; + case KeyEvent.VK_RIGHT: whichNeighbor++; break; + case KeyEvent.VK_D: dump(); break; + case KeyEvent.VK_E: errorNormals = !errorNormals; break; + case KeyEvent.VK_A: hillclimb = false; anneal = !anneal; break; + case KeyEvent.VK_H: anneal = true; hillclimb = !hillclimb; break; + case KeyEvent.VK_N: neighbors = !neighbors; break; + case KeyEvent.VK_T: tileon = !tileon; break; + case KeyEvent.VK_G: goalon = !goalon; break; + case KeyEvent.VK_M: tilemeshon = !tilemeshon; break; + } + } } \ No newline at end of file