checkpoint
authoradam <adam@megacz.com>
Tue, 1 Jul 2008 18:41:16 +0000 (11:41 -0700)
committeradam <adam@megacz.com>
Tue, 1 Jul 2008 18:41:16 +0000 (11:41 -0700)
darcs-hash:20080701184116-5007d-1a5fbf6ced7110203432fc52abe9ef44fde246f8.gz

src/edu/berkeley/qfat/InteractiveMeshViewer.java
src/edu/berkeley/qfat/Main.java
src/edu/berkeley/qfat/Mesh.java
src/edu/berkeley/qfat/MeshViewer.java

index e024d04..d162677 100644 (file)
@@ -11,36 +11,53 @@ import java.util.*;
 import edu.berkeley.qfat.geom.*;
 import edu.berkeley.qfat.geom.Point;
 
 import edu.berkeley.qfat.geom.*;
 import edu.berkeley.qfat.geom.Point;
 
-public class InteractiveMeshViewer extends JPanel {
+public class InteractiveMeshViewer extends JPanel implements KeyListener {
 
     public Mesh tile;
     public Mesh goal;
 
 
     public Mesh tile;
     public Mesh goal;
 
-    private MeshViewer mv;
+    private HashSet<MeshViewer> mvs = new HashSet<MeshViewer>();
 
     public InteractiveMeshViewer(JFrame f) {
 
     public InteractiveMeshViewer(JFrame f) {
-        mv = new MeshViewer();
-        setLayout(new BorderLayout());
-        this.add(mv, BorderLayout.CENTER);
+        MeshViewer mv1 = new MeshViewer();
+        MeshViewer mv2 = new MeshViewer();
+        MeshViewer mv3 = new MeshViewer();
+        MeshViewer mv4 = new MeshViewer();
+        mvs.add(mv1);
+        mvs.add(mv2);
+        mvs.add(mv3);
+        mvs.add(mv4);
+        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() {
         setTile(new Mesh(false));
         setGoal(new Mesh(false));
     }
     public void repaint() {
-        if (mv != null) mv.repaint();
+        if (mvs != null)
+            for(MeshViewer mv : mvs)
+                mv.repaint();
     }
 
 
     public void setTile(Mesh tile) {
     }
 
 
     public void setTile(Mesh tile) {
-        mv.removeMesh(this.tile);
+        for(MeshViewer mv : mvs) mv.removeMesh(this.tile);
         this.tile = tile;
         this.tile = tile;
-        mv.addMesh(this.tile);
+        for(MeshViewer mv : mvs) mv.addMesh(this.tile);
     }
     public void setGoal(Mesh goal) {
     }
     public void setGoal(Mesh goal) {
-        mv.removeMesh(this.goal);
+        for(MeshViewer mv : mvs) mv.removeMesh(this.goal);
         this.goal = goal;
         goal.option_selectable = false;
         goal.option_wireframe = true;
         this.goal = goal;
         goal.option_selectable = false;
         goal.option_wireframe = true;
-        mv.addMesh(this.goal);
+        for(MeshViewer mv : mvs) mv.addMesh(this.goal);
     }
 
     public synchronized void dump() {
     }
 
     public synchronized void dump() {
@@ -83,10 +100,16 @@ public class InteractiveMeshViewer extends JPanel {
     public int accepts;
     public    int vertss;
 
     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()) {
     public void keyPressed(KeyEvent e)  {
         //super.keyPressed(e);
         switch(e.getKeyCode()) {
-            case KeyEvent.VK_SPACE: breaks++; force = true; break;
+            case KeyEvent.VK_SPACE:
+                synchronized(this) {
+                    tile.subdivide();
+                }
+                //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_UP: temp = temp * 2; break;
             case KeyEvent.VK_ENTER: temp = 10; break;
             case KeyEvent.VK_LEFT: whichNeighbor--; break;
index 75b3f12..e4abd5a 100644 (file)
@@ -11,6 +11,31 @@ import edu.berkeley.qfat.geom.Point;
 import edu.berkeley.qfat.geom.Polygon;
 
 // TO DO:
 import edu.berkeley.qfat.geom.Polygon;
 
 // TO DO:
+//
+// - Implement "real" constraints (plane, line, point)
+//
+// - Constrained surface subdivision
+//     - Edge.flip() gets us the triforce subdivision
+//     - Edge.delete() gets us the catmull-clark subdivision
+//     - Catmull-Clark: just don't move points if we can't.  Need to average the influence of the points on a binding group.
+//
+// - Ability to snap three views to orthgonal
+// - SLIDE UI
+//     - left button -> crystal ball
+//     - translate
+//     - rightbutton/mousewheel zoom
+// - v+click to select vertex
+// - show: constraints, bindings, faces
+//
+// Editing:
+//  - fracture edge, face
+//  - change aspect ratio
+//  - ability to select a point, rotate the model, then move the point
+//  - when moving a vertex in one window, show that window's axes in all other windows
+//
+
+
+// TO DO:
 // - real anneal
 // - solve self-intersection problem
 // - get a better test model?
 // - real anneal
 // - solve self-intersection problem
 // - get a better test model?
index 7c38672..f7143f0 100644 (file)
@@ -115,6 +115,22 @@ public class Mesh implements Iterable<Mesh.T> {
     }
 
 
     }
 
 
+    public void subdivide() {
+        for (T t : this) t.old = true;
+        for (Vertex v : vertices()) v.original = true;
+        OUTER: while(true) {
+            for (T t : this)
+                if (t.old) {
+                    Point p = t.e1.midpoint();
+                    System.out.println("shatter " + t.e1);
+                    t.e1.shatter();
+                    nearest(p).edge = true;
+                    continue OUTER;
+                }
+            break;
+        }
+    }
+
     // Vertexices //////////////////////////////////////////////////////////////////////////////
 
     /** a vertex in the mesh */
     // Vertexices //////////////////////////////////////////////////////////////////////////////
 
     /** a vertex in the mesh */
@@ -123,6 +139,9 @@ public class Mesh implements Iterable<Mesh.T> {
         public Point oldp;
         E e;                // some edge *leaving* this point
 
         public Point oldp;
         E e;                // some edge *leaving* this point
 
+        public boolean original = false;
+        public boolean edge = false;
+
         private boolean illegal = false;
 
         public boolean visible = false;
         private boolean illegal = false;
 
         public boolean visible = false;
@@ -752,6 +771,8 @@ public class Mesh implements Iterable<Mesh.T> {
         public final int color;
         public final int colorclass;
 
         public final int color;
         public final int colorclass;
 
+        public boolean old;
+
         public final int serial = max_serial++;
         public boolean occluded;
 
         public final int serial = max_serial++;
         public boolean occluded;
 
index 7a9fcd5..f7fa9c1 100644 (file)
@@ -24,6 +24,7 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
     private Point       clickPoint = null;
     private GLCanvas    glcanvas;
     private boolean     updateVisibilities = false;
     private Point       clickPoint = null;
     private GLCanvas    glcanvas;
     private boolean     updateVisibilities = false;
+    private boolean     mouseInside = false;
 
     private HashSet<Mesh> meshes = new HashSet<Mesh>();
 
 
     private HashSet<Mesh> meshes = new HashSet<Mesh>();
 
@@ -75,6 +76,10 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
 
         GL gl = glcanvas.getGL();//drawable.getGL();
         GLU glu = new GLU();
 
         GL gl = glcanvas.getGL();//drawable.getGL();
         GLU glu = new GLU();
+
+        if (!mouseInside) gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+        else gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glPointSize(5.0f);
         gl.glLoadIdentity();
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glPointSize(5.0f);
         gl.glLoadIdentity();
@@ -185,8 +190,8 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
     public void keyReleased(KeyEvent e) { }
 
     public void mouseClicked(MouseEvent e) { }
     public void keyReleased(KeyEvent e) { }
 
     public void mouseClicked(MouseEvent e) { }
-    public void mouseEntered(MouseEvent e) { }
-    public void mouseExited(MouseEvent e) { }
+    public void mouseEntered(MouseEvent e) { mouseInside = true; }
+    public void mouseExited(MouseEvent e) { mouseInside = false; }
     public void mousePressed(MouseEvent e) {
         clickPoint = getMouse();
     }
     public void mousePressed(MouseEvent e) {
         clickPoint = getMouse();
     }