add items to TODO list
[anneal.git] / src / edu / berkeley / qfat / InteractiveMeshViewer.java
index 10ec045..f87f257 100644 (file)
@@ -8,11 +8,116 @@ import javax.media.opengl.*;
 import javax.media.opengl.glu.*;
 import com.sun.opengl.util.*;
 import java.util.*;
+import edu.berkeley.qfat.bind.*;
 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<MeshViewer> mvs = new HashSet<MeshViewer>();
+
+    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 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 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);
+        switch(e.getKeyCode()) {
+            case KeyEvent.VK_SPACE:
+                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_N: whichNeighbor++; break;
+            case KeyEvent.VK_RIGHT: whichNeighbor++; break;
+            case KeyEvent.VK_D:
+                try {
+                    tile.dump(new FileOutputStream("dump.stl"));
+                } catch (Exception ee) {
+                    throw new RuntimeException(ee);
+                }
+                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;
+        }
+        if (transforms!=null)
+            whichNeighbor = (whichNeighbor % (transforms.length+1));
+    }
+    public Matrix[] transforms;
 }
\ No newline at end of file