/** * Applet allowing interactive investigation of hull algorithms */ import java.applet.*; import java.awt.*; import java.util.*; public class AppletHull extends Applet3d{ Panel mainPanel; Choice modelChoice=null; Choice dataChoice; Choice dataChoice2d; Choice dataChoice3d; Choice dimensionChoice; TextField dataSize; Button moreButton; String moreMessage; Axes axes = new Axes(); Points3d points3d = new Points3d(); private Point3dObject3d[] points = new Point3dObject3d[32]; Viewer makeViewer(){ Viewer v = new Viewer(this); try { String view = getParameter("view"); if (view != null){ View3dInfo home = View3dInfo.fromString(view); v.setHome(home); v.setView(home); } } catch (NumberFormatException e) { } Object3dAdaptor.normalColor=v.addColor("Normal","normal objects",getBoolParameter("Normal"),Color.green,true); Triangle3d.backFaceColor=v.addColor(Color.blue); Object3dAdaptor.addColor=v.addColor("Added","added objects",getBoolParameter("Added"),Color.red,true); Object3dAdaptor.deleteColor=v.addColor("Deleted","deleted objects",getBoolParameter("Deleted"),Color.yellow,true); Axes.color=v.addColor("Axes","coordinate axes",getBoolParameter("Axes"),Color.black,true); Points3d.color=v.addColor("Points","input points",getBoolParameter("Points"),Color.black,true); DivideAndConquer.leftColor=v.addColor("Left Hull","left convex hull",getBoolParameter("Left Hull"),Color.cyan,false); DivideAndConquer.rightColor=v.addColor("Right Hull","right convex hull",getBoolParameter("Right Hull"),Color.magenta,false); Object3dAdaptor.selectColor=v.addColor("Selected","selected object",getBoolParameter("Selected"),Color.cyan,false); dataChoice.select(getParameter("distribution")); dataSize.setText(getParameter("npoints")); setDistribution(); return v; } public void init(){ mainPanel = new Panel(); dimensionChoice = new Choice(); dimensionChoice.addItem("2D"); dimensionChoice.addItem("3D"); mainPanel.add(dimensionChoice); dataChoice3d = new Choice(); dataChoice3d.addItem("In Sphere"); dataChoice3d.addItem("On Sphere"); dataChoice3d.addItem("On Paraboloid"); dataChoice3d.addItem("In Cube"); dataChoice3d.addItem("Gaussian"); dataChoice3d.addItem("Wedge Block"); dataChoice2d = new Choice(); dataChoice2d.addItem("In Circle"); dataChoice2d.addItem("On Circle"); dataChoice2d.addItem("In Square"); dataChoice = dataChoice3d; dataSize = new TextField(Integer.toString(points.length),3); super.init(); mainPanel.add(createModelChoice()); selectDimension(); mainPanel.add(dataSize); mainPanel.add(new Label("Points")); moreButton = new Button(moreMessage="More Controls"); if (!getBoolParameter("vrml")){ mainPanel.add(moreButton); } if (getBoolParameter("controls")){ add("South",mainPanel); } points3d.setLabels(getIntVectorParameter("labels")); int frame = getIntParameter("frame",-1); if (frame!=-1){ viewer.stop(); viewer.setFrameNo(frame); } if (getParameter("Points")!=null) { viewer.setColorVisibility(Points3d.color,getBoolParameter("Points")); } } public void setDistribution(){ int n; String choice =dataChoice.getSelectedItem(); if (choice.equals("Wedge Block")) { n = wedgeBlockData.length; } else { try { n = Math.max(Integer.parseInt(dataSize.getText()),3); } catch (NumberFormatException e) { n = 32; } } Point3d[] pts = new Point3d[n]; Object3dList model = new Object3dList(pts.length); Point3d.setSeed(getIntParameter("seed",(int)System.currentTimeMillis())); if (choice.equals("Wedge Block")) { wedgeBlock(pts); } else if (choice.equals("In Sphere")) { randomInSphere(pts); } else if (choice.equals("On Sphere")) { randomOnSphere(pts); } else if (choice.equals("On Paraboloid")) { randomOnParaboloid(pts); } else if (choice.equals("In Cube")) { randomInCube(pts); } else if (choice.equals("Gaussian")) { randomGaussian(pts); } else if (choice.equals("On Circle")) { randomOnCircle(pts); } else if (choice.equals("In Circle")) { randomInCircle(pts); } else if (choice.equals("In Square")) { randomInSquare(pts); } dataSize.setText(Integer.toString(pts.length)); points = new Point3dObject3d[pts.length]; for (int i=0; i =0){ model.addElement(new Point3dObject3d(points[i],points[i].getSelectFrame())); } } } model.addElement(axes); return model; } /** Set things up for 2D or 3D display */ public void selectDimension(){ if (dimensionChoice.getSelectedItem().equals("2D")) { viewer.setView("Down Z"); viewer.setViewLock(true); viewer.setColorVisibility(Points3d.color,true); mainPanel.remove(dataChoice); mainPanel.add(dataChoice2d,2); dataChoice = dataChoice2d; validate(); } else { viewer.setViewLock(false); viewer.setView("Home"); viewer.setColorVisibility(Points3d.color,false); mainPanel.remove(dataChoice); mainPanel.add(dataChoice3d,2); dataChoice = dataChoice3d; validate(); } } /** defaultModel to display */ public Object3dList defaultModel() { dimensionChoice.select(getParameter("dimension")); modelChoice.select(getParameter("model")); return selectModel(getParameter("model")); } public String[][] getDefaultParameters() { String[][] defaults = { // Array of arrays of strings describing each parameter. // Format: parameter name, value {"bgcolor", "ffffff"}, {"controls", "on"}, {"dimension", "3D"}, {"model","Incremental"}, {"distribution","In Sphere"}, {"npoints","32"}, {"Normal","on"}, {"Added","on"}, {"Deleted","on"}, {"Axes","on"}, {"Left Hull","on"}, {"Right Hull","on"}, {"Selected","on"} }; return defaults; } // Return information suitable for display in an About dialog box. public String getAppletInfo() { return "3D Hull Applet v1.13\nWritten by Tim Lambert."; } public static void main(String[] args){ AppletHull applet = new AppletHull(); applet.setStub(new FakeAppletStub("AppletHull.class?"+args[0]+"&cgi=on")); applet.init(); System.exit(0); } }