change MarchingCubes.march() to take a VoxelData rather than a SampledField
[anneal.git] / src / edu / berkeley / qfat / Main.java
index 4ae3a8e..56eeb83 100644 (file)
@@ -9,6 +9,7 @@ import java.util.*;
 import edu.berkeley.qfat.bind.*;
 import edu.berkeley.qfat.geom.*;
 import edu.berkeley.qfat.stl.*;
+import edu.berkeley.qfat.voxel.*;
 import edu.berkeley.qfat.geom.Point;
 import edu.berkeley.qfat.geom.Polygon;
 
@@ -291,6 +292,32 @@ public class Main extends InteractiveMeshViewer {
         public void hit() {}
     }
 
+    public void marchingCubes() {
+        Mesh mesh = new Mesh(false);
+        mesh.coalesce = true;
+        MarchingCubes.march(new VoxelData() {
+                float radius = 1.0f;
+                public float getMaxX()        { return  1.0f; }
+                public float getMinX()        { return -1.0f; }
+                public int   getNumSamplesX() { return   10; }
+                public float getMaxY()        { return  1.0f; }
+                public float getMinY()        { return -1.0f; }
+                public int   getNumSamplesY() { return   10; }
+                public float getMaxZ()        { return  1.0f; }
+                public float getMinZ()        { return -1.0f; }
+                public int   getNumSamplesZ() { return   10; }
+                public float getSample(Point p) {
+                    double x = p.x;
+                    double y = p.y;
+                    double z = p.z;
+                    return (float)(radius-Math.sqrt(x*x+y*y+z*z));
+                }
+            },
+            mesh);
+        setTile(mesh);
+        //fixupTile();
+    }
+
     public void hexBrick(boolean offset, boolean rotated) {
         setTile(new Mesh(false));
                 float width  = (float)0.8;
@@ -918,11 +945,14 @@ public class Main extends InteractiveMeshViewer {
                     };
                     fixupTile();
                 }}});
+            tileMenu.add(new MyMenuItem("Marching Cubes") { public void hit() {
+                marchingCubes();
+            }});
 
             // Finally, add all the menus to the menu bar.
             add(tileMenu);
-            add(goalMenu);
-            add(hideMenu);
+            //add(goalMenu);
+            //add(hideMenu);
         }
 
     }
@@ -1085,11 +1115,27 @@ public class Main extends InteractiveMeshViewer {
         f.setLayout(new BorderLayout());
         Main main = new Main(f);
         f.add(main, BorderLayout.CENTER);
-        f.setJMenuBar(main.new MyMenuBar());
+
+        f.addWindowListener(new WindowListener() {
+                public void windowActivated(WindowEvent e) { }
+                public void windowClosed(WindowEvent e) { System.exit(0); }
+                public void windowClosing(WindowEvent e) { System.exit(0); }
+                public void windowDeactivated(WindowEvent e)  { }
+                public void windowDeiconified(WindowEvent e)  { }
+                public void windowIconified(WindowEvent e)  { }
+                public void windowOpened(WindowEvent e) { }
+            });
+
         f.pack();
         f.show();
         f.setSize(900, 900);
         f.doLayout();
+
+        JFrame f2 = new JFrame();
+        f2.setJMenuBar(main.new MyMenuBar());
+        f2.setSize(100,100);
+        f2.show();
+
         main.anneal();
     }