X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FInteractiveMeshViewer.java;h=3a2787d7c36502e726225fd71de58d6f34f15399;hb=8ac32254301e142a93899997b5580696d515a8a0;hp=1a72d7ebb2d6f5bb1a1d3fa3bf190704c79d91ff;hpb=2a2e64829786ee415fd0c0f16957c55e174b793b;p=anneal.git diff --git a/src/edu/berkeley/qfat/InteractiveMeshViewer.java b/src/edu/berkeley/qfat/InteractiveMeshViewer.java index 1a72d7e..3a2787d 100644 --- a/src/edu/berkeley/qfat/InteractiveMeshViewer.java +++ b/src/edu/berkeley/qfat/InteractiveMeshViewer.java @@ -11,9 +11,59 @@ import java.util.*; import edu.berkeley.qfat.geom.*; import edu.berkeley.qfat.geom.Point; -public class InteractiveMeshViewer extends MeshViewer { +public class InteractiveMeshViewer extends JPanel implements KeyListener { - public InteractiveMeshViewer(JFrame f) { super(f); } + public Mesh tile; + public Mesh goal; + + private HashSet mvs = new HashSet(); + + public InteractiveMeshViewer(JFrame f) { + MeshViewer mv1 = new MeshViewer(); + MeshViewer mv2 = new MeshViewer(); + MeshViewer mv3 = new MeshViewer(); + MeshViewer mv4 = new MeshViewer(); + mv1.main = (Main)this; + mv2.main = (Main)this; + mv3.main = (Main)this; + mv4.main = (Main)this; + mvs.add(mv1); + mvs.add(mv2); + mvs.add(mv3); + mvs.add(mv4); + f.addKeyListener(this); + addKeyListener(this); + mv1.addKeyListener(this); + mv2.addKeyListener(this); + mv3.addKeyListener(this); + mv4.addKeyListener(this); + setLayout(new GridLayout(2,2)); + this.add(mv1); + this.add(mv2); + this.add(mv3); + this.add(mv4); + setTile(new Mesh(false)); + setGoal(new Mesh(false)); + } + public void repaint() { + if (mvs != null) + for(MeshViewer mv : mvs) + mv.repaint(); + } + + + public void setTile(Mesh tile) { + for(MeshViewer mv : mvs) mv.removeMesh(this.tile); + this.tile = tile; + for(MeshViewer mv : mvs) mv.addMesh(this.tile); + } + public void setGoal(Mesh goal) { + for(MeshViewer mv : mvs) mv.removeMesh(this.goal); + this.goal = goal; + goal.option_selectable = false; + goal.option_wireframe = true; + for(MeshViewer mv : mvs) mv.addMesh(this.goal); + } public synchronized void dump() { try { @@ -35,23 +85,54 @@ public class InteractiveMeshViewer extends MeshViewer { } 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 keyTyped(KeyEvent e) { } + public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { - super.keyPressed(e); + //super.keyPressed(e); switch(e.getKeyCode()) { - case KeyEvent.VK_SPACE: breaks++; force = true; break; + case KeyEvent.VK_SPACE: + System.err.println("hak"); + synchronized(this) { + tile.subdivide(); + tile.rebindPoints(); + break; + } + //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_N: 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_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; } + if (transforms!=null) + whichNeighbor = (whichNeighbor % (transforms.length+1)); } - + public Matrix[] transforms; } \ No newline at end of file